aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/transform_values.rb
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2014-07-12 12:25:27 -0400
committerGuillermo Iguaran <guilleiguaran@gmail.com>2014-07-12 12:25:27 -0400
commit84b4260e6c6238a8bd8ec5880daa8f7b10cfcb14 (patch)
treefb3e6896c26b6a74d2997cbdc672c223fd3fda34 /activesupport/lib/active_support/core_ext/hash/transform_values.rb
parent073397cf5b2ed525f817d06fb9922c147f136860 (diff)
parentf1bad130d0c9bd77c94e43b696adca56c46a66aa (diff)
downloadrails-84b4260e6c6238a8bd8ec5880daa8f7b10cfcb14.tar.gz
rails-84b4260e6c6238a8bd8ec5880daa8f7b10cfcb14.tar.bz2
rails-84b4260e6c6238a8bd8ec5880daa8f7b10cfcb14.zip
Merge pull request #16149 from sferik/refactor-transform_values
Refactor Hash#transform_values and Hash#transform_values!
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/transform_values.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/transform_values.rb4
1 files changed, 3 insertions, 1 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 6ff7e91212..e9bcce761f 100644
--- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb
+++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
@@ -4,7 +4,8 @@ class Hash
#
# { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 }
# # => { a: 2, b: 4, c: 6 }
- def transform_values(&block)
+ def transform_values
+ return enum_for(:transform_values) unless block_given?
result = self.class.new
each do |key, value|
result[key] = yield(value)
@@ -14,6 +15,7 @@ class Hash
# Destructive +transform_values+
def transform_values!
+ return enum_for(:transform_values!) unless block_given?
each do |key, value|
self[key] = yield(value)
end