Class: Hash

Inherits:
Object show all
Defined in:
lib/core_ext/hash/keys.rb

Instance Method Summary collapse

Instance Method Details

#transform_keysObject


2
3
4
5
6
7
8
9
# File 'lib/core_ext/hash/keys.rb', line 2

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

#transform_keys!Object


11
12
13
14
15
16
17
# File 'lib/core_ext/hash/keys.rb', line 11

def transform_keys!
  return enum_for(:transform_keys!) unless block_given?
  keys.each do |key|
    self[yield(key)] = delete(key)
  end
  self
end