replace(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
static VALUE
rb_hash_replace(VALUE hash, VALUE 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;
}