mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure HWIA#reverse_merge! retrurns HWIA [#421 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
committed by
Pratik Naik
parent
8a17fd1a65
commit
aa57e66fec
@@ -91,6 +91,12 @@ class HashWithIndifferentAccess < Hash
|
||||
self.dup.update(hash)
|
||||
end
|
||||
|
||||
# Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
|
||||
# This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.
|
||||
def reverse_merge(other_hash)
|
||||
super other_hash.with_indifferent_access
|
||||
end
|
||||
|
||||
# Removes a specified key from the hash.
|
||||
def delete(key)
|
||||
super(convert_key(key))
|
||||
|
||||
@@ -174,6 +174,13 @@ class HashExtTest < Test::Unit::TestCase
|
||||
assert_equal 2, hash['b']
|
||||
end
|
||||
|
||||
def test_indifferent_reverse_merging
|
||||
hash = HashWithIndifferentAccess.new('some' => 'value', 'other' => 'value')
|
||||
hash.reverse_merge!(:some => 'noclobber', :another => 'clobber')
|
||||
assert_equal 'value', hash[:some]
|
||||
assert_equal 'clobber', hash[:another]
|
||||
end
|
||||
|
||||
def test_indifferent_deleting
|
||||
get_hash = proc{ { :a => 'foo' }.with_indifferent_access }
|
||||
hash = get_hash.call
|
||||
|
||||
Reference in New Issue
Block a user