aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRonak Jangir <ronakjangir47@gmail.com>2015-09-26 21:36:16 +0530
committerRonak Jangir <ronakjangir47@gmail.com>2015-09-28 19:02:56 +0530
commita5e4bcb45e4162869078c1430578cc74b53ade82 (patch)
tree2358551bcca44793bb9c6fc5a506a25d889c76bc /activesupport
parent1d7c8472cfeb024a06284ffe5a5e953aa53832fa (diff)
downloadrails-a5e4bcb45e4162869078c1430578cc74b53ade82.tar.gz
rails-a5e4bcb45e4162869078c1430578cc74b53ade82.tar.bz2
rails-a5e4bcb45e4162869078c1430578cc74b53ade82.zip
Updated docs for transform_values [ci skip]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/transform_values.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/transform_values.rb b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
index e9bcce761f..0aa403377b 100644
--- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb
+++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
@@ -2,8 +2,12 @@ class Hash
# Returns a new hash with the results of running +block+ once for every value.
# The keys are unchanged.
#
- # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 }
- # # => { a: 2, b: 4, c: 6 }
+ # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 } # => { a: 2, b: 4, c: 6 }
+ #
+ # If you do not provide a +block+, it will return an Enumerator
+ # for chaining with other methods:
+ #
+ # { a: 1, b: 2 }.transform_values.with_index { |v, i| [v, i].join.to_i } # => { a: 10, b: 21 }
def transform_values
return enum_for(:transform_values) unless block_given?
result = self.class.new
@@ -13,7 +17,8 @@ class Hash
result
end
- # Destructive +transform_values+
+ # Destructively converts all values using the +block+ operations.
+ # Same as +transform_values+ but modifies +self+.
def transform_values!
return enum_for(:transform_values!) unless block_given?
each do |key, value|