From: 7stud -- Date: 2009-08-27T01:15:05+09:00 Subject: Re: ||= with 1.8 and 1.9 ? Brian Candler wrote: > Aldric Giacomoni wrote: >> It works as indicated. Is this -normal- behavior ? > > FWIW, I get identical results to you using > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux] > ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux] > $ r -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.11.1] $ r9 -v ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin8.11.1] $ r r1test.rb "test" "test" $ r9 r1test.rb "test" "not test" > In ruby 1.8, an attribute writer method (:foo=) always(*) returns the > value of its argument, rather than the last value calculated in the > method, so that you can tell by inspection that > > a = foo.bar = 123 > > will set a to 123. Perhaps it has been decided to change that for 1.9. > If so, then David Black didn't know about it: ------- WARNING Setter methods don't return what you might think. When you use the syntactic sugar that lets you make calls to = methods look like assignments, Ruby takes the assignment semantics seriously. Assignments (like x = 1) evaluate to whatever's on their right-hand side. [On the other hand,] [m]ethods usually return the value of the last expression evaluated during execution. But = method calls behave like assignments: the value of the expression ticket.price = 63.00 is 63.00, even if the 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 ------ A word on Ruby versions The Well Grounded Rubyist is about version 1.9.1 of the Ruby language, the most recent version. ------ p xxvii, The Well Grounded Rubyist -- Posted via http://www.ruby-forum.com/.