Issue #9223 has been updated by tmm1 (Aman Gupta).


r44047 introduced a small change in behavior. Before, reject would copy ivars and default proc into the return hash:

h = {}
h.instance_variable_set(:@foo, 1)
p h.instance_variable_get(:@foo)              #=> 1
p h.reject{true}.instance_variable_get(:@foo) #=> 1

Now, only the class is copied. This can cause subtle issues when a subclass of Hash is used (if it employs ivars).

Note that both the old and new behavior here are completely different than Hash#select, which always returns a plain Hash with no ivars.
----------------------------------------
Bug #9223: Hash#reject!.size does not reflect changes to the hash
https://bugs.ruby-lang.org/issues/9223#change-43602

Author: dmarcotte (Daniel Marcotte)
Status: Closed
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0p353
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


Here's an example demonstrating the issue, comparing to the regular reject behavior:  

h = {a: 'A', b: 'B'}
reject_enum = h.reject
reject_bang_enum = h.reject!
h[:c] = 'C'
p reject_enum.size # 3
p reject_bang_enum.size # 2



-- 
http://bugs.ruby-lang.org/