diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-20 10:13:36 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-20 10:13:36 +0900 |
| commit | 8e91316bd64aa39b3afeffb0ade5eb38b05d3953 (patch) | |
| tree | fabce96f895417c6d2252860211aeb7b4df97a31 /mrbgems/mruby-enumerator | |
| parent | 3820ef791f3ccb766956d12534ae519f4923ac7e (diff) | |
| parent | cb85fa6787ea9467f81be41570a36b475b7ef061 (diff) | |
| download | mruby2-draft.tar.gz mruby2-draft.zip | |
Merge branch 'no-implicit-conversion' into mruby2-draftmruby2-draft
Diffstat (limited to 'mrbgems/mruby-enumerator')
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/enumerator.rb | 12 | ||||
| -rw-r--r-- | mrbgems/mruby-enumerator/test/enumerator.rb | 6 |
2 files changed, 4 insertions, 14 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb index 7ca1d5eb6..ae692dd12 100644 --- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -157,12 +157,10 @@ class Enumerator def with_index(offset=0, &block) return to_enum :with_index, offset unless block - offset = if offset.nil? - 0 - elsif offset.respond_to?(:to_int) - offset.to_int + if offset.nil? + offset = 0 else - raise TypeError, "no implicit conversion of #{offset.class} into Integer" + offset = offset.__to_int end n = offset - 1 @@ -623,9 +621,7 @@ module Enumerable # use Enumerator to use infinite sequence def zip(*args, &block) args = args.map do |a| - if a.respond_to?(:to_ary) - a.to_ary.to_enum(:each) - elsif a.respond_to?(:each) + if a.respond_to?(:each) a.to_enum(:each) else raise TypeError, "wrong argument type #{a.class} (must respond to :each)" diff --git a/mrbgems/mruby-enumerator/test/enumerator.rb b/mrbgems/mruby-enumerator/test/enumerator.rb index 428ea0307..c24b70ccb 100644 --- a/mrbgems/mruby-enumerator/test/enumerator.rb +++ b/mrbgems/mruby-enumerator/test/enumerator.rb @@ -55,12 +55,6 @@ assert 'Enumerator#with_index' do assert_equal [[[1, 10], 20], [[2, 11], 21], [[3, 12], 22]], a end -assert 'Enumerator#with_index nonnum offset' do - s = Object.new - def s.to_int; 1 end - assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a) -end - assert 'Enumerator#with_index string offset' do assert_raise(TypeError){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a } end |
