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
class Fred
@@foo = 99
end
def Fred.foo
class_variable_get(:@@foo)
end
Show source
/*
* call-seq:
* mod.class_variable_get(symbol) => obj
*
* Returns the value of the given class variable (or throws a
* <code>NameError</code> exception). The <code>@@</code> part of the
* variable name should be included for regular class variables
*
* class Fred
* @@foo = 99
* end
*
* def Fred.foo
* class_variable_get(:@@foo) #=> 99
* end
*/
static VALUE
rb_mod_cvar_get(obj, iv)
VALUE obj, iv;
{
ID id = rb_to_id(iv);
if (!rb_is_class_id(id)) {
rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id));
}
return rb_cvar_get(obj, id);
}