From d15550aeccd5c10d7c734c523116e3da9f4b13e8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 20 Mar 2006 18:53:52 +0000 Subject: Fixed the hash.delete :sym (closes #2176) [Stefan Kaes] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4005 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/hash/indifferent_access.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') 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 80012aa17d..d60b605942 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -1,4 +1,6 @@ -# This implementation is HODEL-HASH-9600 compliant +# this class has dubious semantics and we only have it so that +# people can write params[:key] instead of params['key'] + class HashWithIndifferentAccess < Hash def initialize(constructor = {}) if constructor.is_a?(Hash) @@ -24,6 +26,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,11 @@ class HashWithIndifferentAccess < Hash def merge(hash) self.dup.update(hash) end - + + def delete(key) + super(convert_key(key)) + end + protected def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key -- cgit v1.2.3