diff options
| author | ksss <[email protected]> | 2016-12-01 15:29:43 +0900 |
|---|---|---|
| committer | ksss <[email protected]> | 2016-12-01 15:33:27 +0900 |
| commit | 0f774ff4dfc168aa90764b0130d60f14b837cc53 (patch) | |
| tree | 1334783152efc0d8baf654c15c912658a1606756 /mrbgems/mruby-enumerator | |
| parent | 61ac564c99ab07f01f1af2809493103fc5216a85 (diff) | |
| download | mruby-0f774ff4dfc168aa90764b0130d60f14b837cc53.tar.gz mruby-0f774ff4dfc168aa90764b0130d60f14b837cc53.zip | |
Support nil argument as no argument
Diffstat (limited to 'mrbgems/mruby-enumerator')
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/enumerator.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb index 1515a7a89..694ad4270 100644 --- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -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] |
