Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/shadow_puppet/core_ext.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#deep_merge(other_hash) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/shadow_puppet/core_ext.rb', line 7 def deep_merge(other_hash) self.merge(other_hash) do |key, oldval, newval| oldval = oldval.to_hash if oldval.respond_to?(:to_hash) newval = newval.to_hash if newval.respond_to?(:to_hash) oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval end end |
#deep_merge!(other_hash) ⇒ Object
14 15 16 |
# File 'lib/shadow_puppet/core_ext.rb', line 14 def deep_merge!(other_hash) replace(deep_merge(other_hash)) end |
#deep_symbolize_keys ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/shadow_puppet/core_ext.rb', line 17 def deep_symbolize_keys self.inject({}) { |result, (key, value)| value = value.deep_symbolize_keys if value.is_a?(Hash) result[(key.to_sym rescue key) || key] = value result } end |