From: Rick DeNatale Date: 2009-08-27T04:46:34+09:00 Subject: Re: ||= with 1.8 and 1.9 ? On Wed, Aug 26, 2009 at 2:49 PM, Aldric Giacomoni wrote: > Joel VanderWerf wrote: > Well, then... It -IS- assigning something, isn't it, since there's no > value to @test ? Why does it return something other than the result of > the assignment? Right, the question is why in Ruby 1.9 is using the 'not a test' returned from the setter method in the case of ||= unlike Ruby 1.8.x and like itself in the = case: To make it a bit clearer by moving the assignments out of the p calls: 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 p o.test o.test = nil $ 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" I've raised this on ruby-core. I'm interested to see what Matz & co have to say. -- 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