Rick Denatale wrote:
> On Wed, Aug 26, 2009 at 12:15 PM, 7stud --<bbxx789_05ss / yahoo.com> 
> wrote:
>> ticket= method returns the string "Ha ha!" The idea is to keep the
>> semantics consistent. Under the hood, it's a method call; but it looks
>> 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.  

It sounds like you are trying to make a distinction between the sugared 
syntax and the normal method call syntax, but...

class A
  def x
    @x
  end

  def x=(val)
    @x = val
    "Ha, ha!"
  end
end

a1 = A.new
puts a1.x = 10

a2 = A.new
puts a2.x=(10)

--output:--
10
10

both versions return the same thing.


> 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."
>

So are you faulting his use of the phrase "returns the string "Ha, ha!" 
because the method doesn't actually return "Ha, ha!"--it returns 63.00?
-- 
Posted via http://www.ruby-forum.com/.