Skip to content
Permalink
Browse files

Merge pull request #734 from kostya/enum3

fix Enumerator#with_index
  • Loading branch information
alex committed May 24, 2013
2 parents 461af50 + 5045674 commit e48fe7e8288954ebbe15f3f94af761e26c90d721
@@ -17,6 +17,31 @@ def each(&block)
end
end

def each_with_index(&block)
return self.enum_for(:each_with_index) unless block

i = 0
self.each do |*e|
v = (e.size == 1) ? e[0] : e
val = yield(v, i)
i += 1
val
end
end

def with_index(offset = nil, &block)
return self.enum_for(:with_index, offset) unless block
offset = offset ? Topaz.convert_type(offset, Fixnum, :to_int) : 0

i = offset
self.each do |*e|
v = (e.size == 1) ? e[0] : e
val = yield(v, i)
i += 1
val
end
end

def rewind
@object.rewind if @object.respond_to?(:rewind)
@nextvals = nil

This file was deleted.

This file was deleted.

0 comments on commit e48fe7e

Please sign in to comment.
You can’t perform that action at this time.