mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c: exchange semantics of Hash#each and Hash#each_pair.
pointed out by [ruby-dev:30997]. * test/ruby/test_iterator.rb: ditto. * test/ruby/test_yield.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7307d38c4f
commit
afb1901848
4 changed files with 25 additions and 7 deletions
|
@ -359,15 +359,24 @@ class TestIterator < Test::Unit::TestCase
|
|||
|
||||
class H
|
||||
def each
|
||||
yield [:key, :value]
|
||||
end
|
||||
|
||||
def each_pair
|
||||
yield :key, :value
|
||||
end
|
||||
end
|
||||
|
||||
def test_assoc_yield
|
||||
[{:key=>:value}, H.new].each {|h|
|
||||
h.each{|a| assert_equal(:key, a)} # changed at 1.9
|
||||
h.each{|*a| assert_equal([:key, :value], a)}
|
||||
h.each{|k,v| assert_equal([:key, :value], [k,v])}
|
||||
[{:key=>:value}, H.new].each {|h|
|
||||
h.each{|a| assert_equal([:key, :value], a)}
|
||||
h.each{|a,| assert_equal(:key, a)}
|
||||
h.each{|*a| assert_equal([[:key, :value]], a)}
|
||||
h.each{|k,v| assert_equal([:key, :value], [k,v])}
|
||||
h.each_pair{|a| assert_equal(:key, a)}
|
||||
h.each_pair{|a,| assert_equal(:key, a)}
|
||||
h.each_pair{|*a| assert_equal([:key, :value], a)}
|
||||
h.each_pair{|k,v| assert_equal([:key, :value], [k,v])}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue