Skip to content

Instantly share code, notes, and snippets.

@MilanGrubnic70
Last active August 29, 2015 14:00
Show Gist options
  • Save MilanGrubnic70/11097235 to your computer and use it in GitHub Desktop.
Save MilanGrubnic70/11097235 to your computer and use it in GitHub Desktop.

#Variables

###'Local' variables are available in the local scope

###'Block' variables are located in a code block. They are only accessable within the code block.

###'Instance' @variables begin with an @. This isn't just a Ruby convention—it's part of the syntax! Always start your instance variables with @.

###'Class' @@variables are like instance variables, but instead of belonging to an instance of a class, they belong to the class itself. Class variables always start with two @s, like so: @@files.

###'Global' $variables can be declared in two ways. You define the variable outside of any method or class. If you want to make a variable global from inside a method or class, just start it with a $, like so: $matz. Global variables can be changed from anywhere in your program, and they are generally not a very good idea. It's much better to create variables with limited scope that can only be changed from a few places!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment