From c52a473e66632c943f17ab0eba6a96baae06545e Mon Sep 17 00:00:00 2001 From: Alvaro Bautista Date: Sat, 9 Oct 2010 19:45:17 +0200 Subject: [PATCH] Override store method in HashWithIndifferentAccess --- .../active_support/hash_with_indifferent_access.rb | 5 +++++ activesupport/test/core_ext/hash_ext_test.rb | 11 +++++++++++ 2 files changed, 16 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..604104e 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -81,6 +81,11 @@ module ActiveSupport def fetch(key, *extras) super(convert_key(key), *extras) end + + # Associates the given value with the specified key, same as doing hash[key] = value + def store(key, value) + super(convert_key(key), value) + end # Returns an array of the values at the specified indices: # diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 0f35eb9..4b1b884 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -173,6 +173,17 @@ class HashExtTest < Test::Unit::TestCase assert_equal hash[3], 3 end + def test_indifferent_store + hash = HashWithIndifferentAccess.new + hash.store('a', 'string_key_value') + assert_equal 'string_key_value', hash['a'] + assert_equal 'string_key_value', hash[:a] + + hash.store(:a, 'symbol_key_value') + assert_equal 'symbol_key_value', hash[:a] + assert_equal 'symbol_key_value', hash['a'] + end + def test_indifferent_update hash = HashWithIndifferentAccess.new hash[:a] = 'a' -- 1.7.2.2