End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Hash#clear
hash.clear → self
hash.c
View on GitHub ↗
VALUE
rb_hash_clear(VALUE hash)
{
rb_hash_modify_check(hash);
if (RHASH_ITER_LEV(hash) > 0) {
rb_hash_foreach(hash, clear_i, 0);
}
else if (RHASH_AR_TABLE_P(hash)) {
ar_clear(hash);
}
else {
st_clear(RHASH_ST_TABLE(hash));
}
return hash;
}
Removes all hash entries; returns self.