Module: Ettin::DeepTransform

Defined in:
lib/ettin/deep_transform.rb

Overview

Contains the logic for deep transformation of hash keys

Instance Method Summary collapse

Instance Method Details

#deep_transform_keys(&block) ⇒ Object


41
42
43
44
45
46
47
# File 'lib/ettin/deep_transform.rb', line 41

def deep_transform_keys(&block)
  result = {}
  each do |key, value|
    result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
  end
  result
end

#deep_transform_keys!(&block) ⇒ Object


54
55
56
57
58
59
60
# File 'lib/ettin/deep_transform.rb', line 54

def deep_transform_keys!(&block)
  keys.each do |key|
    value = delete(key)
    self[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys!(&block) : value
  end
  self
end