diff options
author | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-26 21:35:57 +0530 |
---|---|---|
committer | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-28 09:33:05 +0530 |
commit | 1d7c8472cfeb024a06284ffe5a5e953aa53832fa (patch) | |
tree | ca74992055f9592eed29295e678dac0a51402c71 /activesupport | |
parent | 7f18ea14c893cb5c9f04d4fda9661126758332b5 (diff) | |
download | rails-1d7c8472cfeb024a06284ffe5a5e953aa53832fa.tar.gz rails-1d7c8472cfeb024a06284ffe5a5e953aa53832fa.tar.bz2 rails-1d7c8472cfeb024a06284ffe5a5e953aa53832fa.zip |
Updated docs for transform_keys [ci skip]
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/keys.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index c30044b9ff..05679f1dd0 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,10 +1,14 @@ class Hash - # Returns a new hash with all keys converted using the block operation. + # Returns a new hash with all keys converted using the +block+ operation. # # hash = { name: 'Rob', age: '28' } # - # hash.transform_keys{ |key| key.to_s.upcase } - # # => {"NAME"=>"Rob", "AGE"=>"28"} + # hash.transform_keys { |key| key.to_s.upcase } # => {"NAME"=>"Rob", "AGE"=>"28"} + # + # If you do not provide a +block+, it will return an Enumerator + # for chaining with other methods: + # + # 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? result = self.class.new @@ -14,8 +18,8 @@ class Hash result end - # Destructively converts all keys using the block operations. - # Same as transform_keys but modifies +self+. + # 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? keys.each do |key| |