Saturday, March 21, 2009

Ruby Variables

  • $global variables are available from anywhere in the program--no matter the object or method, $global will be available.
  • $local variables are only available with the limited context in which they are defined--within a method or block, or if defined outside of a method or block, within whatever self is (a class or module or main).
  • @instance variables are available anywhere within a specific instance of an object.
  • @@class variables are common to all instances of a class. They can be used to count the instance of a class, as shown in the figure above.


1 comment:

Tim said...

Guy! Tim,
That is a remarkably clear figure. Thanks.
Tim (yes the guy who drew the figure)