Method: Hash#transform_keys

Defined in:
lib/croesus/core_ext/hash.rb

#transform_keysHash

Returns a new hash with all keys converted using the block operation.

Examples:

hash = { name: 'Tiggy', age: '15' }

hash.transform_keys{ |key| key.to_s.upcase }
            # => { "AGE" => "15", "NAME" => "Tiggy" }

Returns:



45
46
47
48
49
50
51
52
# File 'lib/croesus/core_ext/hash.rb', line 45

def transform_keys
  enum_for(:transform_keys) unless block_given?
  result = self.class.new
  each_key do |key|
    result[yield(key)] = self[key]
  end
  result
end