зеркало из https://github.com/github/ruby.git
* 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:
Родитель
7307d38c4f
Коммит
afb1901848
|
@ -1,3 +1,12 @@
|
|||
Fri Jun 15 13:24:18 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* 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.
|
||||
|
||||
Fri Jun 15 12:38:29 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* test/ruby/test_iterator.rb: remove debug code (GC.stress=true).
|
||||
|
|
4
hash.c
4
hash.c
|
@ -994,7 +994,7 @@ static int
|
|||
each_pair_i(VALUE key, VALUE value)
|
||||
{
|
||||
if (key == Qundef) return ST_CONTINUE;
|
||||
rb_yield(rb_assoc_new(key, value));
|
||||
rb_yield_values(2, key, value);
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ static int
|
|||
each_i(VALUE key, VALUE value)
|
||||
{
|
||||
if (key == Qundef) return ST_CONTINUE;
|
||||
rb_yield_values(2, key, value);
|
||||
rb_yield(rb_assoc_new(key, value));
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestRubyYield < Test::Unit::TestCase
|
|||
assert_equal 1, v
|
||||
end
|
||||
h.each do |k|
|
||||
assert_equal :a, k # changed at 1.9
|
||||
assert_equal [:a, 1], k
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче