-
-
Save sachsy/ae54b31bbf0da5c71b62 to your computer and use it in GitHub Desktop.
Class Instance Variables in Ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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