Unverified Commit 0f774ff4 authored by ksss's avatar ksss

Support nil argument as no argument

parent 61ac564c
...@@ -153,9 +153,15 @@ class Enumerator ...@@ -153,9 +153,15 @@ class Enumerator
# #
def with_index(offset=0) def with_index(offset=0)
return to_enum :with_index, offset unless block_given? 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| enumerator_block_call do |i|
n += 1 n += 1
yield [i,n] yield [i,n]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment