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_get

mod.class_variable_get(symbol) → obj
mod.class_variable_get(string) → obj

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