From: Peter Lane Date: 2011-12-09T21:39:44+09:00 Subject: Re: CONCEPT OF INSTANCE VARIABLE IN RUBY Manav Gupta wrote in post #1035910: > @x = 'Hello world' > > def printMe > puts @x > end > > int the above code section when a call printMe method it behaves as > expected. However if I remove the '@' symbol making x as a local > variable it throws an undefined name error. which is also as expected. > But can anyone explain me in the previous case, what is the class for > @x. > > Please explain me in details You can find the current object by calling 'self'. If you open irb: 1.9.3p0 :001 > self => main 1.9.3p0 :002 > self.class => Object 1.9.3p0 :003 > self.instance_variables => [:@prompt] 1.9.3p0 :004 > @x = "hello" => "hello" 1.9.3p0 :005 > self.instance_variables => [:@prompt, :@x] You can see @x becomes an instance variable of 'self', which is an instance of the class Object. -- Posted via http://www.ruby-forum.com/.