From: dblack@... Date: 2006-12-15T02:08:01+09:00 Subject: Re: Hi -- On Fri, 15 Dec 2006, Maksim Bartenev wrote: > On 12/14/06, dblack@wobblini.net wrote: >> >> Hi -- >> >> On Fri, 15 Dec 2006, Maksim Bartenev wrote: >> > >> > On 12/14/06, pat eyler wrote: >> >> >> >> On 12/14/06, Maksim Bartenev wrote: >> >> > Hi! >> >> > >> >> > I'm quite new to ruby language. Can anyone please explain why in the >> >> > attached ruby code the setter methods return their argument >> >> > instead of the last statement's value, and the string 'weird >> >> > stuff' gets output only once? >> >> Methods ending with equal signs return the rhs, rather than their last >> value, so that they'll be more assignment-like. That way, this: >> >> x = 1 >> >> and this: >> >> obj.thing = 1 >> >> have very close to the same sematics. >> >> As for 'weird stuff' getting printed only once: it's because you've >> got dummy = true (a local variable assignment) instead of self.dummy = >> true (a call to self.dummy=) in try_dummy2. >> > Thank you for your reply. > > Does this mean that the interpreter uses a different strategy to select a > method depending on whether the message recipient is explicitly specified, > or not? Can you explain in a bit more detail, please? Yes. When it sees this: x = 1 (bareword = value) it always reads that as a local variable assignment. Therefore, = methods always have to have an explicit receiver. David -- Q. What's a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)