Support nil argument as no argument

This commit is contained in:
ksss
2016-12-01 15:29:43 +09:00
parent 61ac564c99
commit 0f774ff4df
@@ -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]