Commit 2b4ed40f authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3185 from kou/string-reduce-needless-array

Reduce needless Array generation in some String methods
parents 3757b16d 6bb0775d
...@@ -354,7 +354,7 @@ class String ...@@ -354,7 +354,7 @@ class String
def chars(&block) def chars(&block)
if block_given? if block_given?
self.split('').map do |i| self.split('').each do |i|
block.call(i) block.call(i)
end end
self self
...@@ -366,7 +366,7 @@ class String ...@@ -366,7 +366,7 @@ class String
def each_char(&block) def each_char(&block)
return to_enum :each_char unless block return to_enum :each_char unless block
split('').map do |i| split('').each do |i|
block.call(i) block.call(i)
end end
self self
...@@ -376,7 +376,7 @@ class String ...@@ -376,7 +376,7 @@ class String
len = self.size len = self.size
if block_given? if block_given?
self.split('').map do|x| self.split('').each do|x|
block.call(x.ord) block.call(x.ord)
end end
self self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment