module GorillaPatch::DeepMerge
Adding deep_merge
method
Public Instance Methods
deep_merge(other_hash, &block)
click to toggle source
# File lib/gorilla_patch/deep_merge.rb, line 21 def deep_merge(other_hash, &block) deep_dup.deep_merge!(other_hash, &block) end
deep_merge!(other_hash, &block)
click to toggle source
# File lib/gorilla_patch/deep_merge.rb, line 9 def deep_merge!(other_hash, &block) other_hash.each do |other_key, other_value| self_value = self[other_key] deep_value_merge!(other_key, self_value, other_value, &block) end self end
deep_value_merge!(other_key, self_value, other_value) { |other_key, self_value, other_value| ... }
click to toggle source
# File lib/gorilla_patch/deep_merge.rb, line 27 def deep_value_merge!(other_key, self_value, other_value, &block) self[other_key] = if self_value.is_a?(Hash) && other_value.is_a?(Hash) self_value.deep_merge!(other_value, &block) elsif block_given? && key?(other_key) yield(other_key, self_value, other_value) else other_value end end