Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/puppet-rest/monkey_patches/hash.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#deep_merge(hash) ⇒ Hash
Merges self with another hash, recursively.
-
#except(*keys) ⇒ Hash
Return a hash that includes everything but the given keys.
-
#except!(*keys) ⇒ Hash
Replaces the hash without the given keys.
- #stringify_keys! ⇒ Object
- #symbolize_keys! ⇒ Object
Instance Method Details
#deep_merge(hash) ⇒ Hash
Merges self with another hash, recursively
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet-rest/monkey_patches/hash.rb', line 24 def deep_merge(hash) target = self.dup hash.keys.each do |key| if hash[key].is_a?(Hash) && self[key].is_a?(Hash) target[key] = target[key].deep_merge(hash[key]) next end target[key] = hash[key] end target end |
#except(*keys) ⇒ Hash
Return a hash that includes everything but the given keys.
7 8 9 |
# File 'lib/puppet-rest/monkey_patches/hash.rb', line 7 def except(*keys) self.dup.except!(*keys) end |
#except!(*keys) ⇒ Hash
Replaces the hash without the given keys.
15 16 17 18 |
# File 'lib/puppet-rest/monkey_patches/hash.rb', line 15 def except!(*keys) keys.each{|key| delete(key)} self end |
#stringify_keys! ⇒ Object
36 37 38 39 40 41 |
# File 'lib/puppet-rest/monkey_patches/hash.rb', line 36 def stringify_keys! keys.each do |key| self[key.to_s] = delete(key) end self end |
#symbolize_keys! ⇒ Object
43 44 45 46 47 48 |
# File 'lib/puppet-rest/monkey_patches/hash.rb', line 43 def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key) || key] = delete(key) end self end |