Created
July 23, 2014 21:36
-
-
Save elricstorm/c4ce3eab62f2e8e64fd0 to your computer and use it in GitHub Desktop.
variables
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
var = "this is a local variable" | |
@var = "this is an instance variable" | |
@@var = "this is a class variable" | |
$var = "this is a global variable" | |
VAR = "this is a constant" | |
def example_one | |
var = "local" | |
p "Yes this #{var} variable can be accessed here" | |
end | |
example_one | |
p var # Cannot access it here. It is not local anymore and will throw an error | |
def example_two | |
@var = "instance" | |
p "Yes this #{@var} variable can be accessed here" | |
end | |
example_two | |
p @var # Yes, this instance variable can be accessed here | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment