This browser does not support basic Web standards, preventing the display of our site's intended design. May we suggest that you upgrade your browser?

Web Development Code Library RubyAllow addition in Hashes

Allow addition in Hashes

Allows you to do 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 }

class Hash
  def +(add)
    temp = {}
    add.each{|k,v| temp[k] = v}
    self.each{|k,v| temp[k] = v}
    temp
  end
end
Excellence. Our Measure. Our Motto. Our Goal.