From: Dave Thomas Date: 2002-08-10T04:30:28+09:00 Subject: Re: ambiguity between local variable assignment and writter method GOTO Kentaro writes: > But what will I get from: puts .setter = 123 Gotoken: I'm guessing that the parser can distinguish the 'start of something' state from the rest (where 'something' is to be discussed :) So, in the case you give Ruby would pass the 'setter' message to the object in the variable 'puts'. However, if we disambiguate with parentheses: puts(.setter = 123) would execute as puts(self.setter = 123) > Well, I know that this probrem is considered one of pit hole. But > this syntax may lead implicitly us to a style: Use @var rather than > var() even if that is a simple attribute. Indeed I prefer @var or > @var=val bacause the semantics of theml are simpler and clearer then > #var() or #var=(val). This is an interesting issue: should internal users go via the setter method or access the instance variable directly. Clearly it depends on the circumstances, but I often find myself writing accessors that do things such as lazy evaluation, or which set dirty flags for persistent objects, and where I really do need to go via the method form. For those times, it's nice to have a shortcut, but it isn't something I'd fight hard for... :) Regards Dave