Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/dokkit/hash.rb

Instance Method Summary collapse

Instance Method Details

#recursive_merge(other_hash, &blk) ⇒ Object

Non-destructive version of Hash#recursive_merge method.



51
52
53
# File 'lib/dokkit/hash.rb', line 51

def recursive_merge(other_hash, &blk)
  dup.recursive_merge!(other_hash, &blk)
end

#recursive_merge!(other_hash, &blk) ⇒ Object

Hash#recursive_merge merges two arbitrarily deep hashes into a single hash. The hash is followed recursively, so that deeply nested hashes that are at the same level will be merged when the parent hashes are merged.



41
42
43
44
45
46
47
48
49
# File 'lib/dokkit/hash.rb', line 41

def recursive_merge!(other_hash, &blk)
  if block_given?
    merge!(other_hash, &blk)
  else
    merge!(other_hash) do |key, value, other_value|
      recursive_store(key, value, other_value)
    end
  end
end