Override #store to be consistent with #[].

[#5775 state:resolved]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
Andrea Campi 2010-10-09 19:28:43 +02:00 committed by Santiago Pastorino
parent 621df2a1ec
commit d80afed620
2 changed files with 12 additions and 0 deletions

View File

@ -45,6 +45,8 @@ module ActiveSupport
regular_writer(convert_key(key), convert_value(value))
end
alias_method :store, :[]=
# Updates the instantized hash with values from the second:
#
# hash_1 = HashWithIndifferentAccess.new

View File

@ -316,6 +316,16 @@ class HashExtTest < Test::Unit::TestCase
assert_equal expected, hash_1
end
def test_store_on_indifferent_access
hash = HashWithIndifferentAccess.new
hash.store(:test1, 1)
hash.store('test1', 11)
hash[:test2] = 2
hash['test2'] = 22
expected = { "test1" => 11, "test2" => 22 }
assert_equal expected, hash
end
def test_reverse_merge
defaults = { :a => "x", :b => "y", :c => 10 }.freeze
options = { :a => 1, :b => 2 }