Method: Hash#transform_keys

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

#transform_keysObject

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"}


30
31
32
33
34
35
36
37
# File 'lib/fancybox2/core_ext/hash.rb', line 30

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