From: "David A. Black" Date: 2008-09-07T02:46:14+09:00 Subject: Re: attr_*, *variables_* Hi -- On Sun, 7 Sep 2008, Thomas B. wrote: > Pedro Silva wrote: >> I prefer the attr* notation, but what really matters is to have a unique >> invocation form. Does anyone think the same? > (Did you mean 'uniform'? Or I don't understand this sentence.) > > I agree that it is good to have one standard, but I think that this is > the case here, more or less. And the standard is to give prefixes when > we perform an action on a prefixed variable, and in attr_* arguments are > not prefixed simply because this action (defining accessors) involves > both the variable, and the newly created method, of which the latter is > not prefixed. So they chose that you sort of specify the method name and > not the attribute name. > > I agree that writing attr_accessor :@a could be regarded as correct as > well, because this would let anybody use the form they find more > coherent with the rest of the methods, and it would seem more clear to a > beginner (I remember my confusion when I first saw it). attr_accessor :@a is ultimately confusing, though, because the attribute is not the instance variable itself; it's implemented with the instance variable. I know that sounds like splitting hairs, but it's important. Attribute is a higher-level concept than instance variable, and it's pieced together in Ruby from instance variables and methods -- so :@a would be mixing in an implementation detail (as would :"a()", for example, even though it might evoke the method-creating side of the attr_* family). David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!