Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Module#class_variable_defined?

(::interned name) -> bool
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