merge!(p1)
public
Adds the contents of other_hash to hsh. If no block is
specified entries with duplicate keys are
overwritten with the values from
other_hash, otherwise the value of each duplicate key is determined by calling the
block with the key, its value in hsh and its value in
other_hash.
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2)
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2) { |key, v1, v2| v1 }
Show source
/*
* call-seq:
* hsh.merge!(other_hash) => hsh
* hsh.update(other_hash) => hsh
* hsh.merge!(other_hash){|key, oldval, newval| block} => hsh
* hsh.update(other_hash){|key, oldval, newval| block} => hsh
*
* Adds the contents of <i>other_hash</i> to <i>hsh</i>. If no
* block is specified entries with duplicate keys are overwritten
* with the values from <i>other_hash</i>, otherwise the value
* of each duplicate key is determined by calling the block with
* the key, its value in <i>hsh</i> and its value in <i>other_hash</i>.
*
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge!(h2)
*
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge!(h2) { |key, v1, v2| v1 }
*
*/
static VALUE
rb_hash_update(hash1, hash2)
VALUE hash1, hash2;
{
hash2 = to_hash(hash2);
if (rb_block_given_p()) {
rb_hash_foreach(hash2, rb_hash_update_block_i, hash1);
}
else {
rb_hash_foreach(hash2, rb_hash_update_i, hash1);
}
return hash1;
}