diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-05 17:32:16 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-05 17:32:16 +0000 |
commit | 12600d77dd1757365dc86e6aec5cafb48ec49886 (patch) | |
tree | e0c2dd9a7ee9e8e8eb3e02be1cd2035d6c7b691b /activesupport/lib | |
parent | c51f9fdc78d1732d6c08a6411ca9d2536aa86d6e (diff) | |
download | rails-12600d77dd1757365dc86e6aec5cafb48ec49886.tar.gz rails-12600d77dd1757365dc86e6aec5cafb48ec49886.tar.bz2 rails-12600d77dd1757365dc86e6aec5cafb48ec49886.zip |
HashWithIndifferentAccess shouldn't confuse false and nil. Closes #5601. Nor should it mistreat legitimate nil values.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4555 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 9af626c8da..9a3b02e5d5 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -10,15 +10,18 @@ class HashWithIndifferentAccess < Hash super(constructor) end end - + def default(key = nil) - value = self[key.to_s] if key.is_a?(Symbol) - value ? value : super + if key.is_a?(Symbol) && include?(key = key.to_s) + self[key] + else + super + end end alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) alias_method :regular_update, :update unless method_defined?(:regular_update) - + def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end @@ -27,7 +30,7 @@ class HashWithIndifferentAccess < Hash other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end - + alias_method :merge!, :update def key?(key) @@ -49,7 +52,7 @@ class HashWithIndifferentAccess < Hash def dup HashWithIndifferentAccess.new(self) end - + def merge(hash) self.dup.update(hash) end @@ -60,7 +63,7 @@ class HashWithIndifferentAccess < Hash def stringify_keys!; self end def symbolize_keys!; self end - + protected def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key |