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_defined?
obj.class_variable_defined?(symbol) → true or false
obj.class_variable_defined?(string) → true or false
object.c
View on GitHub ↗
static VALUE
rb_mod_cvar_defined(VALUE obj, VALUE iv)
{
ID id = id_for_var(obj, iv, class);
if (!id) {
return Qfalse;
}
return rb_cvar_defined(obj, id);
}
Returns true if the given class variable is defined in obj. String arguments are converted to symbols.
Example
class Fred @@foo = 99 end Fred.class_variable_defined?(:@@foo) #=> true Fred.class_variable_defined?(:@@bar) #=> false
See also
#class_exec
#class_variable_get
#class_eval
#class_variables
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0