aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorMark McSpadden <markmcspadden@gmail.com>2012-05-23 12:31:35 -0500
committerMark McSpadden <markmcspadden@gmail.com>2012-05-23 13:11:06 -0500
commit2b5b60fc3c4251536b837937391ebdd028892b15 (patch)
tree94f6cbd72dba9be3f9bf15e422f6d45642dc7122 /guides/source
parent541429fbe49b0671adb3842ab1818230d670ef9f (diff)
downloadrails-2b5b60fc3c4251536b837937391ebdd028892b15.tar.gz
rails-2b5b60fc3c4251536b837937391ebdd028892b15.tar.bz2
rails-2b5b60fc3c4251536b837937391ebdd028892b15.zip
Add Hash#deep_transform_keys and Hash#deep_transform_keys! Also convert deep_*_keys to use deep_transform_keys.
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!+