Maintenance Ruby 3.3 gets fixes, but no new features. 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 (hash_iterating_p(hash)) {
rb_hash_foreach(hash, clear_i, 0);
}
else if (RHASH_AR_TABLE_P(hash)) {
ar_clear(hash);
}
else {
st_clear(RHASH_ST_TABLE(hash));
compact_after_delete(hash);
}
return hash;
}
Removes all hash entries; returns self.