Module: NCCO::Utils

Defined in:
lib/ncco/utils.rb

Class Method Summary collapse

Class Method Details

.deep_transform_keys(hash) {|the| ... } ⇒ Hash

Transforms the keys of a Hash with the provided block recursively, walking through nested hashes

Yield Parameters:

  • the

    key to transform



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ncco/utils.rb', line 11

def self.deep_transform_keys(hash, &block)
  result = {}

  hash.each do |key, value|
    result[yield(key)] = if value.is_a?(Hash)
                           deep_transform_keys(value, &block)
                         else
                           value
                         end
  end

  result
end

.deep_transform_keys_to_symbols(hash) ⇒ Object

Transforms the keys of Hash into symbols recursively, walking through nested hashes



28
29
30
# File 'lib/ncco/utils.rb', line 28

def self.deep_transform_keys_to_symbols(hash)
  deep_transform_keys(hash, &:to_sym)
end