initialize_copy(p1)
public
Replaces the contents of hsh with the contents of
other_hash.
h = { "a" => 100, "b" => 200 }
h.replace({ "c" => 300, "d" => 400 })
Show source
/*
* call-seq:
* hsh.replace(other_hash) -> hsh
*
* Replaces the contents of <i>hsh</i> with the contents of
* <i>other_hash</i>.
*
* h = { "a" => 100, "b" => 200 }
* h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
*
*/
static VALUE
rb_hash_replace(hash, hash2)
VALUE hash, hash2;
{
hash2 = to_hash(hash2);
if (hash == hash2) return hash;
rb_hash_clear(hash);
rb_hash_foreach(hash2, replace_i, hash);
RHASH(hash)->ifnone = RHASH(hash2)->ifnone;
if (FL_TEST(hash2, HASH_PROC_DEFAULT)) {
FL_SET(hash, HASH_PROC_DEFAULT);
}
else {
FL_UNSET(hash, HASH_PROC_DEFAULT);
}
return hash;
}