From: Zhao Yi Date: 2008-09-02T21:46:36+09:00 Subject: Re: About class variable question? Stefano Crocco wrote: > On Tuesday 02 September 2008, Zhao Yi wrote: >> h.say > @name is an instance variable of the Hello object, not of instances of > Hello, > such as h. To create an instance variable of instances of Hello, you > need to > assign it a value in an instance method. Usually, this is done in the > initialize method: > > class Hello > > def initialize > @name = "Hello" > end > > def say > puts "Hello" + @name > end > > end > > h = Hello.new > h.say > > I hope this helps > > Stefano If the name is Hello object instance, it should be accessed by Hello object, right? see this code: class Hello @name="world" def name @name end end h=Hello.new puts h.name It will print "nil" which means the first line of this class @name="world" is ignored. Am I right? -- Posted via http://www.ruby-forum.com/.