diff options
author | Eileen M. Uchitelle <eileencodes@gmail.com> | 2015-11-07 11:27:17 -0500 |
---|---|---|
committer | Eileen M. Uchitelle <eileencodes@gmail.com> | 2015-11-07 11:27:17 -0500 |
commit | 24bddfc542cf218e395029db3ece4502ae79eb3d (patch) | |
tree | 0bd1c2e494c2222f5b8f8320844aae15d1c9c0ef /activesupport/lib | |
parent | 986f79a446f73c6e093419f751222768e1ccd13c (diff) | |
parent | 9addcbb00a77d6fbbb10ac242b8455a28b8f3631 (diff) | |
download | rails-24bddfc542cf218e395029db3ece4502ae79eb3d.tar.gz rails-24bddfc542cf218e395029db3ece4502ae79eb3d.tar.bz2 rails-24bddfc542cf218e395029db3ece4502ae79eb3d.zip |
Merge pull request #21806 from kachick/fix-transformer-size
Return a sized Enumerator from Hash#transform_values{!}
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/keys.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/transform_values.rb | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 07a282e8b6..8b2366c4b3 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -10,7 +10,7 @@ class Hash # # hash.transform_keys.with_index { |k, i| [k, i].join } # => {"name0"=>"Rob", "age1"=>"28"} def transform_keys - return enum_for(:transform_keys) unless block_given? + return enum_for(:transform_keys) { size } unless block_given? result = self.class.new each_key do |key| result[yield(key)] = self[key] @@ -21,7 +21,7 @@ class Hash # Destructively converts all keys using the +block+ operations. # Same as +transform_keys+ but modifies +self+. def transform_keys! - return enum_for(:transform_keys!) unless block_given? + return enum_for(:transform_keys!) { size } unless block_given? keys.each do |key| self[yield(key)] = delete(key) end 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 9ddb838774..7d507ac998 100644 --- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb +++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb @@ -9,7 +9,7 @@ class Hash # # { 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? + return enum_for(:transform_values) { size } unless block_given? return {} if empty? result = self.class.new each do |key, value| @@ -21,7 +21,7 @@ class Hash # 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? + return enum_for(:transform_values!) { size } unless block_given? each do |key, value| self[key] = yield(value) end |