diff options
author | Lucas HĂșngaro <lucashungaro@gmail.com> | 2012-04-29 15:43:06 -0300 |
---|---|---|
committer | Lucas HĂșngaro <lucashungaro@gmail.com> | 2012-05-23 11:56:10 -0300 |
commit | a4bb195c91fa9bb25e136aa8850f3acafea0a597 (patch) | |
tree | 64a71bae017ae2a6d5fc701eff2dfd8e57b05cd0 /guides/source/active_support_core_extensions.textile | |
parent | c1487f619045840d89f1e2dbc6e133e1c2cbf2f4 (diff) | |
download | rails-a4bb195c91fa9bb25e136aa8850f3acafea0a597.tar.gz rails-a4bb195c91fa9bb25e136aa8850f3acafea0a597.tar.bz2 rails-a4bb195c91fa9bb25e136aa8850f3acafea0a597.zip |
Adding deep versions of stringify_keys and symbolize_keys (plain and bang) for nested hashes
Diffstat (limited to 'guides/source/active_support_core_extensions.textile')
-rw-r--r-- | guides/source/active_support_core_extensions.textile | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 1f92d9d5f5..e2118e8f61 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -2611,6 +2611,13 @@ The second line can safely access the "type" key, and let the user to pass eithe There's also the bang variant +stringify_keys!+ that stringifies keys in the very receiver. +Besides that, one can use +deep_stringify_keys+ and +deep_stringify_keys!+ to stringify all the keys in the given hash and all the hashes nested into it. An example of the result is: + +<ruby> +{nil => nil, 1 => 1, :nested => {:a => 3, 5 => 5}}.deep_stringify_keys +# => {""=>nil, "1"=>1, "nested"=>{"a"=>3, "5"=>5}} +</ruby> + NOTE: Defined in +active_support/core_ext/hash/keys.rb+. h5. +symbolize_keys+ and +symbolize_keys!+ @@ -2645,6 +2652,13 @@ The second line can safely access the +:params+ key, and let the user to pass ei There's also the bang variant +symbolize_keys!+ that symbolizes keys in the very receiver. +Besides that, one can use +deep_symbolize_keys+ and +deep_symbolize_keys!+ to symbolize all the keys in the given hash and all the hashes nested into it. An example of the result is: + +<ruby> +{nil => nil, 1 => 1, "nested" => {"a" => 3, 5 => 5}}.deep_symbolize_keys +# => {nil=>nil, 1=>1, :nested=>{:a=>3, 5=>5}} +</ruby> + NOTE: Defined in +active_support/core_ext/hash/keys.rb+. h5. +to_options+ and +to_options!+ |