From ac50b633d4b9fd12bf0212a5cf8ebc5ab3ee8f37 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 26 May 2012 22:24:06 -0500 Subject: add examples to Hash#deep_stringify_keys and Hash#deep_symbolize_keys [ci skip] --- activesupport/lib/active_support/core_ext/hash/keys.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- cgit v1.2.3