mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c: move implementation of each_slice, each_cons,
each_with_object to enum.c. * enum.c (each_slice_i): convert multiple values from yield into an array. * enum.c (each_cons_i): ditto. * enum.c (each_with_object_i): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b386fe21ec
commit
78a59da8bc
4 changed files with 167 additions and 150 deletions
|
@ -197,6 +197,14 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
assert(!([1,2,3].member?(4)))
|
||||
end
|
||||
|
||||
class Foo
|
||||
include Enumerable
|
||||
def each
|
||||
yield 1
|
||||
yield 1,2
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_with_index
|
||||
a = []
|
||||
@obj.each_with_index {|x, i| a << [x, i] }
|
||||
|
@ -207,6 +215,7 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
hash[item] = index
|
||||
end
|
||||
assert_equal({"cat"=>0, "wombat"=>2, "dog"=>1}, hash)
|
||||
assert_equal([[1, 0], [[1, 2], 1]], Foo.new.each_with_index.to_a)
|
||||
end
|
||||
|
||||
def test_each_with_object
|
||||
|
@ -217,17 +226,11 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
}
|
||||
assert_same(obj, ret)
|
||||
assert_equal([55, 3628800], ret)
|
||||
end
|
||||
|
||||
class Foo
|
||||
include Enumerable
|
||||
def each
|
||||
yield 1
|
||||
yield 1,2
|
||||
end
|
||||
assert_equal([[1, nil], [[1, 2], nil]], Foo.new.each_with_object(nil).to_a)
|
||||
end
|
||||
|
||||
def test_each_entry
|
||||
assert_equal([1, 2, 3], [1, 2, 3].each_entry.to_a)
|
||||
assert_equal([1, [1, 2]], Foo.new.each_entry.to_a)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue