Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/foundry/refinements/hash.rb
Instance Method Summary collapse
- #deep_merge(other) ⇒ Object
- #deep_merge!(other) ⇒ Object
- #without(*keys) ⇒ Object
- #without!(*keys) ⇒ Object
Instance Method Details
#deep_merge(other) ⇒ Object
2 3 4 |
# File 'lib/foundry/refinements/hash.rb', line 2 def deep_merge(other) dup.deep_merge!(other) end |
#deep_merge!(other) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/foundry/refinements/hash.rb', line 6 def deep_merge!(other) other.each_pair do |other_key, other_value| this_value = self[other_key] if this_value.is_a?(Hash) && other_value.is_a?(Hash) self[other_key] = this_value.deep_merge(other_value) else self[other_key] = other_value end end self end |
#without(*keys) ⇒ Object
18 19 20 |
# File 'lib/foundry/refinements/hash.rb', line 18 def without(*keys) dup.without!(*keys) end |
#without!(*keys) ⇒ Object
22 23 24 |
# File 'lib/foundry/refinements/hash.rb', line 22 def without!(*keys) self.reject! { |key, _| keys.include?(key) }; self end |