Module: KOSapiClient::HashUtils

Defined in:
lib/kosapi_client/hash_utils.rb

Class Method Summary collapse

Class Method Details

.deep_transform_hash_keys(item, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/kosapi_client/hash_utils.rb', line 4

def self.deep_transform_hash_keys(item, &block)
  return item unless item.is_a?(Hash)
  copy = {}
  item.each do |key, value|
    new_value = deep_transform_hash_keys(value, &block) if value.is_a? Hash
    new_value = value.map { |it| deep_transform_hash_keys(it, &block) }  if value.is_a? Array
    new_value ||= value
    copy[block.call(key)] = new_value
  end
  copy
end