diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-07-05 01:09:40 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-07-05 01:09:40 +0000 |
commit | 760bcc6ea93d235294cb741a2359365794365c34 (patch) | |
tree | 507873cfcb9f2e31c58a209c84010683cddf7603 /activesupport/lib | |
parent | f384622a20bfa701b5bce9582ce58d8235ed0185 (diff) | |
download | rails-760bcc6ea93d235294cb741a2359365794365c34.tar.gz rails-760bcc6ea93d235294cb741a2359365794365c34.tar.bz2 rails-760bcc6ea93d235294cb741a2359365794365c34.zip |
Fixed HashWithIndifferentAccess#default (closes #5586) [chris@seagul.co.uk]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4539 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 11 |
1 files changed, 7 insertions, 4 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 1f645fabc9..9af626c8da 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -11,9 +11,10 @@ class HashWithIndifferentAccess < Hash end end - def default(key) - self[key.to_s] if key.is_a?(Symbol) - end + def default(key = nil) + value = self[key.to_s] if key.is_a?(Symbol) + value ? value : super + end alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) alias_method :regular_update, :update unless method_defined?(:regular_update) @@ -74,7 +75,9 @@ module ActiveSupport #:nodoc: module Hash #:nodoc: module IndifferentAccess #:nodoc: def with_indifferent_access - HashWithIndifferentAccess.new(self) + hash = HashWithIndifferentAccess.new(self) + hash.default = self.default + hash end end end |