A local variable starts with a lowercase letter or an underscore (_). Local variables do not contain nil values like global and real variables before initialization.
ruby> $foo
Nil
ruby> @foo
nil
ruby> foo
ERR: (eval): 1:undefined local variable or method ' Foo ' for Main (Object)
The first assignment of a local variable is done much like a declaration. If you point to an uninitialized local variable, the Ruby interpreter thinks it is the name of a method; as seen above
of information.
In general, the range of local variables will be
proc{...}
loop{...}
Def... End
Class...end
module...end
Entire program (unless one of the above conditions is met)
The following example, define? is an operator that checks whether an identifier has been defined. If it is defined, it returns a description of the identifier, or nil. As you can see, the bar range is
The local variable of the loop; bar is undefined when the loop exits.
ruby> foo = 44; Print Foo, "n"; Defined? Foo
"local-variable"
ruby> loop{bar=45 print Bar, "n"; break}; defined bar
nil