From: 7stud -- Date: 2009-04-29T07:14:29+09:00 Subject: Re: Why does attr_accessor in module require 'self.'? 7stud -- wrote: > Ryan Davis wrote: >> On Apr 28, 2009, at 05:26 , 7stud -- wrote: >> >>> John Barnette wrote: >>>> >>>> It's because Ruby automatically creates local variables upon >>>> assignment. Given a class with a method "foo": >>>> >>> >>> Can attr_accessor ever apply to variables that don't begin with @? >> >> no, otherwise it'd be named something else. > > Well, then what's all this talk about "the parser sees this, and the > parser does that". The op never tries to access an instance variable in > the classs, so the fact that a call to attr_accessor is in the class is > irrelevant. End of story. Hmm...not quite: class B end b = B.new puts b.a --output:-- undefined method `a' for # (NoMethodError) class B attr_accessor :a end b = B.new puts b.a nil -- Posted via http://www.ruby-forum.com/.