diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-03 11:58:39 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2016-12-03 11:58:39 +0900 |
| commit | d89cfca02c2f632cef443442339136b89ff15017 (patch) | |
| tree | d58add6e0192b205b5a34c276df92153bc271f45 /mrbgems/mruby-enumerator/mrblib/enumerator.rb | |
| parent | e673fbb35a0c439bb4685cd0a6784f93a4856c07 (diff) | |
| parent | 2718fed1248872e6af436159a8f336fb54b86df2 (diff) | |
| download | mruby-d89cfca02c2f632cef443442339136b89ff15017.tar.gz mruby-d89cfca02c2f632cef443442339136b89ff15017.zip | |
Merge pull request #3315 from ksss/enumerator-with_index
Fix some incompatibility for Enumerator#with_index
Diffstat (limited to 'mrbgems/mruby-enumerator/mrblib/enumerator.rb')
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/enumerator.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb index 1515a7a89..89b66cd45 100644 --- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -153,12 +153,18 @@ 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 - enumerator_block_call do |i| + n = offset - 1 + enumerator_block_call do |*i| n += 1 - yield [i,n] + yield i.__svalue, n end end |
