End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Module#class_variable_get
mod.class_variable_get(symbol) → obj
mod.class_variable_get(string) → obj
object.c
View on GitHub ↗
static VALUE
rb_mod_cvar_get(VALUE obj, VALUE iv)
{
ID id = id_for_var(obj, iv, class);
if (!id) {
rb_name_err_raise("uninitialized class variable %1$s in %2$s",
obj, iv);
}
return rb_cvar_get(obj, id);
}
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.
Example
class Fred @@foo = 99 end Fred.class_variable_get(:@@foo) #=> 99
See also
#class_variable_defined?
#class_variables
#class_exec
#class_variable_set
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0