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)
{
rb_hash_modify_check(hash);
if (hash == hash2) return hash;
hash2 = to_hash(hash2);
COPY_DEFAULT(hash, hash2);
rb_hash_clear(hash);
if (RHASH_AR_TABLE_P(hash)) {
if (RHASH_AR_TABLE_P(hash2)) {
ar_copy(hash, hash2);
}
else {
goto st_to_st;
}
}
else {
if (RHASH_AR_TABLE_P(hash2)) ar_force_convert_table(hash2, __FILE__, __LINE__);
st_to_st:
RHASH_TBL_RAW(hash)->type = RHASH_ST_TABLE(hash2)->type;
rb_hash_foreach(hash2, replace_i, hash);
}
return hash;
}