Skip to content

Commit

Permalink
Refactor Array#each
Browse files Browse the repository at this point in the history
  • Loading branch information
suzukaze committed Dec 26, 2015
1 parent a060bd5 commit 8807690
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mrblib/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8807690

Please sign in to comment.