From: Rick DeNatale Date: 2009-08-27T09:46:18+09:00 Subject: Re: ||= with 1.8 and 1.9 ? On Wed, Aug 26, 2009 at 7:00 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: ||= with 1.8 and 1.9 ?" >    on Thu, 27 Aug 2009 01:20:20 +0900, Rick DeNatale writes: > > |a = b = c > | > | is treated the same as > | > |b = c; a = c > | > |in other words the result of the b= is ignored. > > No, > >  a = b = c > > is parsed as > >  a = (b = c) Yes, I was speaking a bit loosely and was trying to say just what you said next > so, result of the latter assignment is used for the former assignment. > The point is when b here is an attribute assignment (e.g. foo.b = c), > the result value from the setter method (b=) is ignored. And I think that the really important point here is that a.b ||= c should have have the same effect as a.b || a.b = c And that it's surprising that in Ruby 1.9 it doesn't puts RUBY_VERSION class OrOrEquals def test @test end def test=(test) @test = test 'not test' end end o = OrOrEquals.new direct = o.test = 'a test' p direct o.test = nil with_oror = o.test ||= 'a test' p with_oror with_or_or_assign = o.test || o.test = "a test" p with_or_or_assign $ multiruby or_or_equals.rb /opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:144: warning: /Users/rick/.gem/ruby/1.8/specifications: Permission denied VERSION = 1.8.6-p368 CMD = ~/.multiruby/install/1.8.6-p368/bin/ruby or_or_equals.rb 1.8.6 "a test" "a test" "a test" RESULT = 0 VERSION = 1.8.7-p160 CMD = ~/.multiruby/install/1.8.7-p160/bin/ruby or_or_equals.rb 1.8.7 "a test" "a test" "a test" RESULT = 0 VERSION = 1.9.1-p0 CMD = ~/.multiruby/install/1.9.1-p0/bin/ruby or_or_equals.rb 1.9.1 "a test" "not test" "a test" RESULT = 0 -- 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