Skip to content

Instantly share code, notes, and snippets.

@elricstorm
Created July 23, 2014 21:36
Show Gist options
  • Save elricstorm/c4ce3eab62f2e8e64fd0 to your computer and use it in GitHub Desktop.
Save elricstorm/c4ce3eab62f2e8e64fd0 to your computer and use it in GitHub Desktop.
variables
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