check if array shrinks in each block

This commit is contained in:
Yukihiro Matz Matsumoto
2013-01-16 18:32:04 +09:00
parent 98d364e4a6
commit 79d38c4962
+7 -1
View File
@@ -12,7 +12,13 @@ class Array
def each(&block)
idx, length = -1, self.length-1
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
self
end