Module: MightyGrid::MgHash

Defined in:
lib/mighty_grid/mighty_grid_ext.rb

Class Method Summary collapse

Class Method Details

.rec_merge(hash, other) ⇒ Object

A deep merge of two hashes. That is, if both hashes have the same key and the values are hashes, these two hashes should also be merged. Used for merging two sets of params.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mighty_grid/mighty_grid_ext.rb', line 7

def rec_merge(hash, other)  #:nodoc:
  res = hash.clone
  other.each do |key, other_value|
    value = res[key]
    if value.is_a?(Hash) && other_value.is_a?(Hash)
      res[key] = rec_merge value, other_value
    else
      res[key] = other_value
    end
  end
  res
end