Replace all of the pairs in h with those from another hash : replace « Hash « Ruby






Replace all of the pairs in h with those from another hash


h = {}        # Start with an empty hash
h[:a] = 1     # Map :a=>1.  h is now {:a=>1}
h.store(:b,2) # More verbose: h is now {:a=>1, :b=>2}

h.replace({1=>:a, 2=>;b}  # h is now equal to the argument hash

 








Related examples in the same category

1.Replace a hash with another key-value pair
2.Replace hash with a constant