inspec/lib/utils/hash.rb
Dominik Richter 4852842bf6 feature: add hash utility for deep_merge
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
2015-09-22 02:15:42 +02:00

11 lines
253 B
Ruby

# encoding: utf-8
# Inspired by: http://stackoverflow.com/a/9381776
class ::Hash
def deep_merge(second)
merger = proc { |_key, v1, v2|
v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2
}
merge(second, &merger)
end
end