From f38e752bdf27668faf1125479f815832484c0a72 Mon Sep 17 00:00:00 2001 From: David Graham Date: Tue, 16 Oct 2012 13:05:25 -0600 Subject: Implement replace method so key? works correctly. --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 0c78f1611f..306d80b2df 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -204,6 +204,14 @@ module ActiveSupport replace(reverse_merge( other_hash )) end + # Replaces the contents of this hash with other_hash. + # + # h = { "a" => 100, "b" => 200 } + # h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400} + def replace(other_hash) + super(self.class.new_from_hash_copying_default(other_hash)) + end + # Removes the specified key from the hash. def delete(key) super(convert_key(key)) -- cgit v1.2.3