diff options
author | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-26 21:36:16 +0530 |
---|---|---|
committer | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-28 19:02:56 +0530 |
commit | a5e4bcb45e4162869078c1430578cc74b53ade82 (patch) | |
tree | 2358551bcca44793bb9c6fc5a506a25d889c76bc | |
parent | 1d7c8472cfeb024a06284ffe5a5e953aa53832fa (diff) | |
download | rails-a5e4bcb45e4162869078c1430578cc74b53ade82.tar.gz rails-a5e4bcb45e4162869078c1430578cc74b53ade82.tar.bz2 rails-a5e4bcb45e4162869078c1430578cc74b53ade82.zip |
Updated docs for transform_values [ci skip]
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/transform_values.rb | 11 |
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| |