mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Support nil argument as no argument
This commit is contained in:
@@ -153,9 +153,15 @@ class Enumerator
|
||||
#
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user