Class: CfnMonitor::Utils
- Inherits:
-
Object
- Object
- CfnMonitor::Utils
- Defined in:
- lib/cfn_monitor/utils.rb
Class Method Summary collapse
-
.deep_merge(a, b) ⇒ Object
Merge Hash B into hash A.
Class Method Details
.deep_merge(a, b) ⇒ Object
Merge Hash B into hash A. If any values or hashes as well, merge will be performed recursively Returns Hash A with updated values
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cfn_monitor/utils.rb', line 6 def self.deep_merge(a, b) # Loop over key/value pairs b.each { |key, value| # If key from B present in map A if a.key? key # If both are hashes call recursively if (a[key].class == Hash and b[key].class == Hash) a[key] = deep_merge(a[key], value) else # Overwrite value with value from B a[key] = value end else # Add key from B a[key] = value end } # Return hash a return a end |