Skip to content

Instantly share code, notes, and snippets.

@mcordell
Created August 1, 2013 17:58
Show Gist options
  • Save mcordell/6133685 to your computer and use it in GitHub Desktop.
Save mcordell/6133685 to your computer and use it in GitHub Desktop.
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