From: Glenn Jackman Date: 2009-08-27T02:10:13+09:00 Subject: Re: ||= with 1.8 and 1.9 ? At 2009-08-26 11:00AM, "Aldric Giacomoni" wrote: > A friend of mine on Twitter recently posted this tidbit of code: > > class OrOrEquals > def test > @test > end > > def test=(test) > @test = test > 'not test' > end > end > > p (OrOrEquals.new.test = 'test') > # ruby 1.8 returns 'test' > # ruby 1.9 returns 'test' > > p (OrOrEquals.new.test ||= 'test') > # ruby 1.8 returns 'test' > # ruby 1.9 returns 'not test' > > It works as indicated. Is this -normal- behavior ? Not only that, this odd behaviour only happens for ||= and not for plain = $ cat orequal.rb puts RUBY_VERSION class OrOrEquals def test @test end def test=(test) @test = test 'not test' end end o = OrOrEquals.new p o.test = 'a test' o.test = nil p o.test ||= 'a test' $ ruby orequal.rb 1.8.7 "a test" "a test" $ ruby19 orequal.rb 1.9.1 "a test" "not test" -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous