check if array shrinks in each block

parent 98d364e4
...@@ -12,7 +12,13 @@ class Array ...@@ -12,7 +12,13 @@ class Array
def each(&block) def each(&block)
idx, length = -1, self.length-1 idx, length = -1, self.length-1
while(idx < length) while(idx < length)
block.call(self[idx += 1]) elm = self[idx += 1]
unless elm
if elm == nil and length >= self.length
break
end
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