aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/keys.rb
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-26 22:24:06 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-26 22:24:06 -0500
commitac50b633d4b9fd12bf0212a5cf8ebc5ab3ee8f37 (patch)
treee350cc1ad9dc7c31922196e29eef0ca61a78c852 /activesupport/lib/active_support/core_ext/hash/keys.rb
parent7d8474e20a7c3ee720c2659e52d1862dcd8b368d (diff)
downloadrails-ac50b633d4b9fd12bf0212a5cf8ebc5ab3ee8f37.tar.gz
rails-ac50b633d4b9fd12bf0212a5cf8ebc5ab3ee8f37.tar.bz2
rails-ac50b633d4b9fd12bf0212a5cf8ebc5ab3ee8f37.zip
add examples to Hash#deep_stringify_keys and Hash#deep_symbolize_keys [ci skip]
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/keys.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/keys.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index e5e77bcef4..988a0b5949 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -93,6 +93,11 @@ class Hash
# Return a new hash with all keys converted to strings.
# This includes the keys from the root hash and from all
# nested hashes.
+ #
+ # hash = { person: { name: 'Rob', age: '28' } }
+ #
+ # hash.deep_stringify_keys
+ # # => { "person" => { "name" => "Rob", "age" => "28" } }
def deep_stringify_keys
deep_transform_keys{ |key| key.to_s }
end
@@ -107,6 +112,11 @@ class Hash
# Return a new hash with all keys converted to symbols, as long as
# they respond to +to_sym+. This includes the keys from the root hash
# and from all nested hashes.
+ #
+ # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
+ #
+ # hash.deep_symbolize_keys
+ # # => { person: { name: "Rob", age: "28" } }
def deep_symbolize_keys
deep_transform_keys{ |key| key.to_sym rescue key }
end