On Wed, Aug 26, 2009 at 1:30 PM, Rick DeNatale<rick.denatale / gmail.com> wrote:
> This came up on the ruby lang forum.
>
> This seems like a 1.9 bug. Is it?
>
>
> ---------- Forwarded message ----------
> From: Aldric Giacomoni <aldric / trevoke.net>
> Date: Wed, Aug 26, 2009 at 11:00 AM
> Subject: ||= with 1.8 and 1.9 ?
> To: ruby-talk ML <ruby-talk / ruby-lang.org>
>
>
> A friend of mine on Twitter recently posted this tidbit of code:
>
> class OrOrEquals
>   
>  
>  
>
>   >   
> not test'
>  
> 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 ?

And another test:

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 believe that the 1.8.x behavior is correct is it not?  The return
value of the setter should be discarded and the value of the rhs
expression should be used shouldn't it?
-- 
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