Module: HashExtend
- Included in:
- Hash
- Defined in:
- lib/rails_highcharts/hash_extend.rb
Overview
h = {:a=>1, :b=>{:c=>3, :d=>{:e=>4}}} =
h1 = {:a=>1, :b=>{:g=>6, :d=>{:f=>5}}} =
a = h.merge_recursive(h1) =
a = {:a=>1, :b=>{:c=>3, :d=>{:e=>4, :f=>5}, :g=>6}} =
Instance Method Summary collapse
-
#merge_recursive(hash) ⇒ Object
extend the Hash class to allow for recursive merging.
Instance Method Details
#merge_recursive(hash) ⇒ Object
extend the Hash class to allow for recursive merging
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails_highcharts/hash_extend.rb', line 11 def merge_recursive(hash) result = Marshal.load(Marshal.dump(self)) hash.keys.each do |key|s if hash[key].is_a?(Hash) and self[key].is_a?(Hash) result[key] = result[key].deep_merge(hash[key]) next end result[key] = hash[key] end # return the merged result hash result end |