Class: FormatParser::HashUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_utils.rb

Class Method Summary collapse

Class Method Details

.deep_transform_keys(object, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hash_utils.rb', line 6

def self.deep_transform_keys(object, &block)
  case object
  when Hash
    object.each_with_object({}) do |(key, value), result|
      result[yield(key)] = deep_transform_keys(value, &block)
    end
  when Array
    object.map { |e| deep_transform_keys(e, &block) }
  else
    object
  end
end