Sometimes you only want to temporarily do an add, and this is how I pulled it off:
class Hash def +(add) temp = {} add.each{|k,v| temp[k] = v} self.each{|k,v| temp[k] = v} temp end end
Now you can do stuff like:
x = { :a => 1 } y = { :b => 2 } # x + y => { :a => 1, :b => 2 }, but x and y are untouched # x + { :c => 3 } => { :a => 1, :c => 3 }
If you want to force an add, it's easy:
x += y => { :a => 1, :b => 2 } (this is now what x contains)
mergemethod. Try this instead:class Hash
def +(other)
merge(other)
end
end