diff options
author | Xavier Noria <fxn@hashref.com> | 2013-09-07 01:33:19 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-09-07 01:33:19 -0700 |
commit | c989a18a74d970be86c537766f14916bd06fe176 (patch) | |
tree | cf2ab71e426364c6b82e884b00146acf1345abc1 /guides/source/active_support_core_extensions.md | |
parent | 6a91a3307ff6556225ab8717617074cea20222e0 (diff) | |
parent | 2c8bc2cdcdb7b144b7a583d24922fd8064bcff3d (diff) | |
download | rails-c989a18a74d970be86c537766f14916bd06fe176.tar.gz rails-c989a18a74d970be86c537766f14916bd06fe176.tar.bz2 rails-c989a18a74d970be86c537766f14916bd06fe176.zip |
Merge pull request #12155 from jetthoughts/reformat_guides_code_examples
Use Ruby on Rails Coding Conventions for code examples in the guides
Diffstat (limited to 'guides/source/active_support_core_extensions.md')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index ca023f7f66..fa32fc898e 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2736,14 +2736,14 @@ NOTE: Defined in `active_support/core_ext/hash/except.rb`. The method `transform_keys` accepts a block and returns a hash that has applied the block operations to each of the keys in the receiver: ```ruby -{nil => nil, 1 => 1, a: :a}.transform_keys{ |key| key.to_s.upcase } +{nil => nil, 1 => 1, a: :a}.transform_keys { |key| key.to_s.upcase } # => {"" => nil, "A" => :a, "1" => 1} ``` The result in case of collision is undefined: ```ruby -{"a" => 1, a: 2}.transform_keys{ |key| key.to_s.upcase } +{"a" => 1, a: 2}.transform_keys { |key| key.to_s.upcase } # => {"A" => 2}, in my test, can't rely on this result though ``` @@ -2751,11 +2751,11 @@ This method may be useful for example to build specialized conversions. For inst ```ruby def stringify_keys - transform_keys{ |key| key.to_s } + transform_keys { |key| key.to_s } end ... def symbolize_keys - transform_keys{ |key| key.to_sym rescue key } + transform_keys { |key| key.to_sym rescue key } end ``` @@ -2764,7 +2764,7 @@ There's also the bang variant `transform_keys!` that applies the block operation 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 => nil, 1 => 1, nested: {a: 3, 5 => 5}}.deep_transform_keys { |key| key.to_s.upcase } # => {""=>nil, "1"=>1, "NESTED"=>{"A"=>3, "5"=>5}} ``` |