Skip to content
Permalink
Browse files
Refactor Array#each
  • Loading branch information
suzukaze committed Dec 26, 2015
1 parent a060bd5 commit 88076901fda5edd312b198c89493a39e4c840ade
Showing 1 changed file with 4 additions and 7 deletions.
@@ -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

0 comments on commit 8807690

Please sign in to comment.