ActiveSupport Hash#dup

Please do PR. This is a delicate behavior change, so let’s take care that the hashes are indeed separate objects, defaults are preserved correctly, etc.

Hi, Jeremy.

It seemed to be a good idea, but then I realized that it is actually not that good.

Because:

h={'test' => 123, ttt: 1234} # => {"test"=>123, :ttt=>1234}
h=h.with_indifferent_access # => {"test"=>123, "ttt"=>1234}
h.except(:ttt) # => {"test"=>123}
h.except2(:ttt) # => {"test"=>123, "ttt"=>1234}

As we can see, except2 method has different behaviour then except method. However I think I can fix it.

class HashWithIndifferentAccess < Hash
def except2(keys )
dup.except!(
keys)
end
end
h={‘test’ => 123, ttt: 1234} # => {“test”=>123, :ttt=>1234}
h=h.with_indifferent_access # => {“test”=>123, “ttt”=>1234}
h.except(:ttt) # => {“test”=>123}
h.except2(:ttt) # => {“test”=>123}


What do you think about it?

Regards, Dmitry.

Good catch. Do we have test coverage for these cases already?

I have found “test_deep_merge_on_indifferent_access”. However there is no test for except method for these cases.