lib/madvertise/ext/hash.rb in madvertise-ext-0.2.2 vs lib/madvertise/ext/hash.rb in madvertise-ext-0.3.0
- old
+ new
@@ -10,11 +10,22 @@
newval = newval.to_hash if newval.respond_to?(:to_hash)
oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval
end
end
- # Recursively merge and replace +other_hash+ into +self.
+ # Recursively merge and replace +other_hash+ into +self+.
def deep_merge!(other_hash)
replace(deep_merge(other_hash))
+ end
+
+ # accumulate existing keys from +other_hash+ into +self+.
+ def delta_merge!(other_hash)
+ other_hash.each do |k,v|
+ if self.has_key?(k)
+ self[k] += v
+ else
+ self[k] = v
+ end
+ end
end
end