On Wed, Aug 26, 2009 at 12:15 PM, 7stud --<bbxx789_05ss / yahoo.com> wrote:
> If so, then David Black didn't know about it:
>
> -------
> WARNING Setter methods don't return what you might think.  > use the syntactic sugar that lets you make calls to = methods look like
> assignments, Ruby takes the assignment semantics seriously.  
> (like x = 1) evaluate to whatever's on their right-hand side.   > other hand,] [m]ethods usually return the value of the last expression
> evaluated during execution.      
> the value of the expression ticket.price = 63.00 is 63.00, even if the
> ticket= method returns the string "Ha ha!"       > semantics consistent.      > like an assignment and behaves like an assignment with respect to its
> value as an expression.
> ------
> p. 72, The Well Grounded Rubyist

I know what David is getting at here, but that first sentence isn't
exactly true, although I'll grant a pedagogical license for it.

It's not that the return value isn't what you think, it's that it's
ignored when the setter method is called from the sugary syntax of an
assignment.  Note that he says that ticket.price = 63.00 evaluates to
63.00 "even if the ticket= method returns the string "Ha Ha!".  Which
is different than saying ticket= returns 63.00 instead of "what you
might think."

And Brian's example of using send demonstrates that it's the
assignment and not the method call result which isn't what you think.


-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale