Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/nifty_settings/settings.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other_hash, &block) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/nifty_settings/settings.rb', line 158

def deep_merge(other_hash, &block)
  self.dup.tap do |this_hash|
    other_hash.each_pair do |k, v|
      tv = this_hash[k]
      this_hash[k] = case
      when tv.is_a?(Hash) && v.is_a?(Hash)
        tv.deep_merge(v, &block)
      when block_given? && tv
        block.call(k, tv, v)
      else
        v
      end
    end
  end
end