diff options
author | Rashmi Yadav <rays.rashmi@gmail.com> | 2014-08-23 21:44:03 +0200 |
---|---|---|
committer | Rashmi Yadav <rays.rashmi@gmail.com> | 2014-08-23 21:44:03 +0200 |
commit | 078cc10d31ee39fa8960e6f491dbea3b368cbec7 (patch) | |
tree | 9d17e0deb63c98da6199783afec1471110d781f8 /guides | |
parent | ed7e8751542e72e360a80221321d69fa144a181c (diff) | |
download | rails-078cc10d31ee39fa8960e6f491dbea3b368cbec7.tar.gz rails-078cc10d31ee39fa8960e6f491dbea3b368cbec7.tar.bz2 rails-078cc10d31ee39fa8960e6f491dbea3b368cbec7.zip |
[ci skip ]Document transform_values && transform_values!
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 5ed392d43d..08b46c62eb 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2862,6 +2862,20 @@ Active Record does not accept unknown options when building associations, for ex NOTE: Defined in `active_support/core_ext/hash/keys.rb`. +### Transform Values + +#### `transform_values` && `transform_values!` + +The method `transform_values` accepts a block and returns a hash that has applied the block operations to each of the values in the receiver + +```ruby +{nil => nil, 1 => 1, a: :a}.transform_values { |value| value.to_s.upcase } +# => {nil => "", 1 => "1", :a=> "A"} +``` +There's also the bang variant `transform_values!` that applies the block operations to values in the very receiver. + +NOTE: Defined in `active_support/core_text/hash/transform_values.rb` + ### Slicing Ruby has built-in support for taking slices out of strings and arrays. Active Support extends slicing to hashes: |