diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-16 23:48:24 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-16 23:48:24 +0000 |
commit | 05a5209f823f18e423e320f6bce4a91532c8bd03 (patch) | |
tree | 18b50ddd859036456f8c6ef8d4168d8bfd5f9f10 /activesupport/lib/active_support | |
parent | 0fc805697564b4b730b37ea9d1400dcbaad8e323 (diff) | |
download | rails-05a5209f823f18e423e320f6bce4a91532c8bd03.tar.gz rails-05a5209f823f18e423e320f6bce4a91532c8bd03.tar.bz2 rails-05a5209f823f18e423e320f6bce4a91532c8bd03.zip |
HashWithIndifferentAccess#to_hash converts to a Hash with String keys and the same default value. Fix Hash#reverse_update to be an alias for reverse_merge./script/console More thoroughly test the reverse_* methods.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5725 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/reverse_merge.rb | 4 |
2 files changed, 8 insertions, 3 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 9a3b02e5d5..6c7e6d76ac 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,4 @@ -# this class has dubious semantics and we only have it so that +# This class has dubious semantics and we only have it so that # people can write params[:key] instead of params['key'] class HashWithIndifferentAccess < Hash @@ -64,6 +64,11 @@ class HashWithIndifferentAccess < Hash def stringify_keys!; self end def symbolize_keys!; self end + # Convert to a Hash with String keys. + def to_hash + Hash.new(default).merge(self) + end + protected def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key diff --git a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb index 46c53871d8..3c4908ac9e 100644 --- a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb @@ -18,8 +18,8 @@ module ActiveSupport #:nodoc: replace(reverse_merge(other_hash)) end - alias_method :reverse_update, :reverse_merge + alias_method :reverse_update, :reverse_merge! end end end -end
\ No newline at end of file +end |