mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #3062 from suzukaze/refactor-array-each
Refactor Array#each
This commit is contained in:
+4
-7
@@ -12,13 +12,10 @@ class Array
|
||||
def each(&block)
|
||||
return to_enum :each unless block_given?
|
||||
|
||||
idx, length = -1, self.length-1
|
||||
while idx < length and length <= self.length and length = self.length-1
|
||||
elm = self[idx += 1]
|
||||
if elm.nil? and length >= self.length
|
||||
break
|
||||
end
|
||||
block.call(elm)
|
||||
idx = 0
|
||||
while idx < length
|
||||
block.call(self[idx])
|
||||
idx += 1
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user