mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 22:14:37 +02:00
hash.c: rb_hash_reject without dup
* hash.c (rb_hash_reject): copy unrejected elements only to new hash, so that the change on the original receiver can affect. [ruby-core:58914] [Bug #9223] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77280b6cd6
commit
7416073cde
3 changed files with 30 additions and 4 deletions
|
@ -501,9 +501,13 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
|
||||
def test_size_for_enum_created_from_hash
|
||||
h = {a: 1, b: 2, c: 3}
|
||||
%i[delete_if reject! select select! keep_if each each_key each_pair].each do |method|
|
||||
assert_equal 3, h.send(method).size
|
||||
end
|
||||
methods = %i[delete_if reject reject! select select! keep_if each each_key each_pair]
|
||||
enums = methods.map {|method| h.send(method)}
|
||||
s = enums.group_by(&:size)
|
||||
assert_equal([3], s.keys, ->{s.reject!{|k| k==3}.inspect})
|
||||
h[:d] = 4
|
||||
s = enums.group_by(&:size)
|
||||
assert_equal([4], s.keys, ->{s.reject!{|k| k==4}.inspect})
|
||||
end
|
||||
|
||||
def test_size_for_enum_created_from_env
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue