remove_class_variable(p1)
public
Removes the definition of the sym, returning that constant’s
value.
class Dummy
@@var = 99
puts @@var
remove_class_variable(:@@var)
p(defined? @@var)
end
produces:
99
nil
Show source
VALUE
rb_mod_remove_cvar(VALUE mod, VALUE name)
{
const ID id = id_for_var_message(mod, name, class, "wrong class variable name %1$s");
st_data_t val, n = id;
if (!id) {
not_defined:
rb_name_err_raise("class variable %1$s not defined for %2$s",
mod, name);
}
rb_check_frozen(mod);
if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &val)) {
return (VALUE)val;
}
if (rb_cvar_defined(mod, id)) {
rb_name_err_raise("cannot remove %1$s for %2$s", mod, ID2SYM(id));
}
goto not_defined;
}