From: Brian Candler Date: 2011-12-12T18:17:39+09:00 Subject: Re: CONCEPT OF INSTANCE VARIABLE IN RUBY La Wi wrote in post #1036024: > If your program consists entirely of this code: > > @x = 'hello' > def printMe > puts x > puts @x > end ... > x is a local variable whose scope is limited to printMe(), and is > undefined. No, that's not quite right. x here is a method call, not a local variable, because there has been no assignment to x earlier in the scope (in this case the body of method 'printMe'). That is: puts x is interpreted as if you had written puts self.x or puts x() However, if you had written instead: def printMe if false x = 123 end puts x end then x would indeed be a local variable, and its value is 'nil' (because the assignment which occurs earlier in the scope is not actually executed) Regards, Brian. -- Posted via http://www.ruby-forum.com/.