class_variable_get(p1)
public
Returns the value of the given class variable (or throws a NameError exception). The @@ part of the
variable name should be included for regular class variables. String arguments are converted to symbols.
class Fred
@@foo = 99
end
Fred.class_variable_get(:@@foo)
Show source
static VALUE
rb_mod_cvar_get(VALUE obj, VALUE iv)
{
ID id = rb_check_id(&iv);
if (!id) {
if (rb_is_class_name(iv)) {
rb_name_error_str(iv, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"",
iv, rb_class_name(obj));
}
else {
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
QUOTE(iv));
}
}
if (!rb_is_class_id(id)) {
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
QUOTE_ID(id));
}
return rb_cvar_get(obj, id);
}