Skip to content

Commit

Permalink
Support nil argument as no argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Dec 1, 2016
1 parent 61ac564 commit 0f774ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mrbgems/mruby-enumerator/mrblib/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ def initialize_copy(obj)
#
def with_index(offset=0)
return to_enum :with_index, offset unless block_given?
raise TypeError, "no implicit conversion of #{offset.class} into Integer" unless offset.respond_to?(:to_int)
offset = if offset.nil?
0
elsif offset.respond_to?(:to_int)
offset.to_int
else
raise TypeError, "no implicit conversion of #{offset.class} into Integer"
end

n = offset.to_int - 1
n = offset - 1
enumerator_block_call do |i|
n += 1
yield [i,n]
Expand Down

0 comments on commit 0f774ff

Please sign in to comment.