[LRUG] attr_accessor parsed as a method variable when setting with a get

Sean O'Halpin sean.ohalpin at gmail.com
Wed Sep 21 13:14:38 PDT 2011


> A question of taste. If I've defined public accessors, my preference is to use them even within methods of that object, rather than touching the instance variable directly. I like this because a) it encapsulates access to that piece of state, in case I want to provide a default or otherwise wrap reads/writes to the instance variable, and b) instance variables are ugly innit.

I agree with you and do pretty much the same though I think it's more
than a matter of taste. Direct access to an instance variable is a
privilege that you shouldn't invoke unless you absolutely need it.

Asked why globals and instance variables looked so ugly, Matz said he
made them that way to discourage people from using them.
Unfortunately, years of fugly Rails templates have inured people to
seeing them.

Also, Matz has said that one of his biggest regrets was not making
accessors take priority over local variables.



More information about the Chat mailing list