Skip to content

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

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