Skip to content
Permalink
Browse files
Support nil argument as no argument
  • Loading branch information
ksss committed Dec 1, 2016
1 parent 61ac564 commit 0f774ff4dfc168aa90764b0130d60f14b837cc53
Showing 1 changed file with 8 additions and 2 deletions.
@@ -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]

0 comments on commit 0f774ff

Please sign in to comment.