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 = rb_check_id(&name);
st_data_t val, n = id;
if (!id) {
if (rb_is_class_name(name)) {
rb_name_error_str(name, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"",
name, rb_class_name(mod));
}
else {
rb_name_error_str(name, "wrong class variable name %"PRIsVALUE"", QUOTE(name));
}
}
if (!rb_is_class_id(id)) {
rb_name_error(id, "wrong class variable name %"PRIsVALUE"", QUOTE_ID(id));
}
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_error(id, "cannot remove %"PRIsVALUE" for %"PRIsVALUE"",
QUOTE_ID(id), rb_class_name(mod));
}
rb_name_error(id, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"",
QUOTE_ID(id), rb_class_name(mod));
UNREACHABLE;
}