aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-23 11:41:58 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-23 11:41:58 -0700
commit7a23ada0e5b30e4b511be7a39385121255503e2a (patch)
treecc015acd11a3ab3d13748d79aef115e1bc7b0ce8 /guides/source
parent82b05fbcf4869517c08fb62398b03f3f133c0a28 (diff)
parent2b5b60fc3c4251536b837937391ebdd028892b15 (diff)
downloadrails-7a23ada0e5b30e4b511be7a39385121255503e2a.tar.gz
rails-7a23ada0e5b30e4b511be7a39385121255503e2a.tar.bz2
rails-7a23ada0e5b30e4b511be7a39385121255503e2a.zip
Merge pull request #6466 from markmcspadden/hash_deep_transform_keys
Add Hash#deep_transform_keys and Hash#deep_transform_keys! Also convert ...
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/active_support_core_extensions.textile7
1 files changed, 7 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index e2118e8f61..587f65529e 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -2579,6 +2579,13 @@ end
There's also the bang variant +transform_keys!+ that applies the block operations to keys in the very receiver.
+Besides that, one can use +deep_transform_keys+ and +deep_transform_keys!+ to perform the block operation on 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_transform_keys{ |key| key.to_s.upcase }
+# => {""=>nil, "1"=>1, "NESTED"=>{"A"=>3, "5"=>5}}
+</ruby>
+
NOTE: Defined in +active_support/core_ext/hash/keys.rb+.
h5. +stringify_keys+ and +stringify_keys!+