Hi -- On Thu, 27 Aug 2009, 7stud -- wrote: > 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? I think that's the sentence he feels I got right, as opposed to the first one. His point is that you can use send to show what the method is actually returning: >> def x=(y); "hi"; end => nil >> self.x = 1 => 1 >> send(:x=,1) => "hi" So that my first sentence should be "Calls to setter methods don't always produce the results you might think they would" or something like that. David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Q: What's the best way to get a really solid knowledge of Ruby? A: Come to our Ruby training in Edison, New Jersey, September 14-17! Instructors: David A. Black and Erik Kastner More info and registration: http://rubyurl.com/vmzN