Commit d10e304d authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #3062 from suzukaze/refactor-array-each

Refactor Array#each
parents 6218b2e0 88076901
...@@ -12,13 +12,10 @@ class Array ...@@ -12,13 +12,10 @@ class Array
def each(&block) def each(&block)
return to_enum :each unless block_given? return to_enum :each unless block_given?
idx, length = -1, self.length-1 idx = 0
while idx < length and length <= self.length and length = self.length-1 while idx < length
elm = self[idx += 1] block.call(self[idx])
if elm.nil? and length >= self.length idx += 1
break
end
block.call(elm)
end end
self self
end end
......
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