From: jake kaiden Date: 2011-10-19T04:58:36+09:00 Subject: Re: Local and Global Variable hi Junayeed, check out this link for more info on ruby variables and constants... http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Variables_and_Constants in general, global variables are a bad idea - and it's best to try and stay away from them if you can. you'll soon discover why yourself, as you continue to use ruby more. class, instance, and local variables will usually cover all your needs. class variables exist and are the same across all instances and methods of a given class. instance variables exist and can be accessed from all methods of an instance of a class, but are not shared by two instances of the same class (changing one will not change the other.) local variables exist only within the method or block in which they were created. here's a quick comparison of instance variables and local variables: ####### class VariableTester def initialize @instance = "I can travel between methods of this class" local = "I only exist in the `initialize` method" puts @instance puts local print_variables end def print_variables local = "I'm also called `local,` and I only exist in the `print_variables` method" puts puts @instance puts local @instance = "I've been changed!" print_again end def print_again local = "I'm yet another local, and I can't leave the `print_again` method." puts puts @instance puts local end end vt = VariableTester.new ####### hth, - j -- Posted via http://www.ruby-forum.com/.