On Wed, Aug 26, 2009 at 3:46 PM, Rick DeNatale<rick.denatale / gmail.com> wrote:
> 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:

According the rubyspec project:

  language/variables_spec.rb:
    describe "Operator assignment 'var op= expr'" do
      it "is equivalent to 'var = var op expr'" do
        x = nil
        (x ||= 17).should == 17
        x.should == 17
        (x ||= 2).should == 17
        x.should == 17
    describe "Operator assignment 'obj.meth op= expr'" do
      it "is equivalent to 'obj.meth = obj.meth op expr'" do
        @x.a = nil
        (@x.a ||= 17).should == 17
        @x.a.should == 17
        (@x.a ||= 2).should == 17
        @x.a.should == 17
    describe "Operator assignment 'obj[idx] op= expr'" do
      it "is equivalent to 'obj[idx] = obj[idx] op expr'" do
        x = [1,nil,12]
        (x[1] ||= 17).should == 17
        x.should == [1,17,12]
        (x[1] ||= 2).should == 17
        x.should == [1,17,12]
      it "returns result of rhs not result of []=" do
        a = VariablesSpecs::Hashalike.new
        (a[123] =   2).should == 2
        (a[123] ||= 2).should == 123
        (a[nil] ||= 2).should == 2

The specs don't address the case of a 'hijacked' setter, but they do
give the impression that the ruby1.9 behaviour is incorrect.

> I've raised this on ruby-core.  I'm interested to see what Matz & co
> have to say.

Yes, should be interesting.