From 8282a5ef0b85aa7c5993071d444654337b325ce1 Mon Sep 17 00:00:00 2001 From: Andrea Campi Date: Sat, 9 Oct 2010 19:28:43 +0200 Subject: [PATCH] Override #store to be consistent with #[]. [#5775 state:resolved] --- .../active_support/hash_with_indifferent_access.rb | 2 ++ activesupport/test/core_ext/hash_ext_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index e8215bc..c406dd3 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -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 diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 0f35eb9..545fed2 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -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 } -- 1.7.2