Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Class Instance Variables in Ruby.
class ClassVarTest
@variable = "Class Variable"
def self.get_class_variable
@variable
end
def get_object_variable
@variable
end
def define_variable
@variable = "Instance Variable"
end
end
> ClassVarTest.get_class_variable
=> "Class Variable"
> object = ClassVarTest.new
> object.get_object_variable
=> nil
> object.define_variable
> object.get_object_variable
=> "Instance Variable"
> ClassVarTest.get_class_variable
=> "Class Variable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.