Issue #8052 has been updated by gcao (Guoliang Cao).


My bad :-D

I was so excited that I found a bug in Ruby... just kidding.
----------------------------------------
Bug #8052: "prepend Mod1, Mod2" behaves strangely
https://bugs.ruby-lang.org/issues/8052#change-37402

Author: gcao (Guoliang Cao)
Status: Rejected
Priority: Normal
Assignee: 
Category: core
Target version: 
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]


I did some quick experiment with prepend and noticed a strange behavior.

"prepend B; prepend C" and "prepend B, C" produce same ancestors. However, their behaviors are different. 

IMHO, "prepend B, C" should just insert B and C into ancestors array(or something equivalent) in the same order as appeared in code. Because 'prepend' is like inverse of 'include', it should work like "prepend C; prepend B". From this point of view the behavior I see with 'prepend B, C' in below code is a bug.

Please feel free to let me know if I misunderstood the feature.

Thanks,
Cao

(({
module B
  def test
    puts 'before B'
    super
    puts 'after B'
  end
end

module C
  def test
    puts 'before C'
    super
    puts 'after C'
  end
end

class A
  prepend B
  prepend C

  def test
    puts 'A'
  end
end

class AA
  prepend B, C

  def test
    puts 'AA'
  end
end

puts "prepend B; prepend C   => #{A.ancestors}\n\n"
A.new.test

puts "\n\nprepend B, C    => #{A.ancestors}\n\n"
AA.new.test

__END__
prepend B; prepend C   => [C, B, A, Object, Kernel, BasicObject]

before C
before B
A
after B
after C


prepend B, C    => [C, B, A, Object, Kernel, BasicObject]

before B
before C
AA
after C
after B
}))


-- 
http://bugs.ruby-lang.org/