merge(p1)
public
Returns a new hash containing the contents of
other_hash and the contents of hsh, overwriting entries
in hsh with duplicate keys with
those from other_hash.
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge(h2)
h1
Show source
/*
* call-seq:
* hsh.merge(other_hash) -> a_hash
* hsh.merge(other_hash){|key, oldval, newval| block} -> a_hash
*
* Returns a new hash containing the contents of <i>other_hash</i> and
* the contents of <i>hsh</i>, overwriting entries in <i>hsh</i> with
* duplicate keys with those from <i>other_hash</i>.
*
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge(h2) #=> {"a"=>100, "b"=>254, "c"=>300}
* h1 #=> {"a"=>100, "b"=>200}
*
*/
static VALUE
rb_hash_merge(hash1, hash2)
VALUE hash1, hash2;
{
return rb_hash_update(rb_obj_dup(hash1), hash2);
}