Forum: Ruby-core [ruby-trunk - Bug #8052][Open] "prepend Mod1, Mod2" behaves strangely

6f67bf7db5209823d24a3720746047f6?d=identicon&s=25 gcao (Guoliang Cao) (Guest)
on 2013-03-08 20:40
(Received via mailing list)
Issue #8052 has been reported by gcao (Guoliang Cao).

----------------------------------------
Bug #8052: "prepend Mod1, Mod2" behaves strangely
https://bugs.ruby-lang.org/issues/8052

Author: gcao (Guoliang Cao)
Status: Open
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
}))
0e610136db92027148906c92d57fdb36?d=identicon&s=25 marcandre (Marc-Andre Lafortune) (Guest)
on 2013-03-08 21:31
(Received via mailing list)
Issue #8052 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

Your test has a bug. The last puts should use `AA.ancestors`.

You would see that `prepend B, C` is equivalent to `prepend C; prepend
B` (as per the documentation).
----------------------------------------
Bug #8052: "prepend Mod1, Mod2" behaves strangely
https://bugs.ruby-lang.org/issues/8052#change-37401

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
}))
6f67bf7db5209823d24a3720746047f6?d=identicon&s=25 gcao (Guoliang Cao) (Guest)
on 2013-03-08 21:37
(Received via mailing list)
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
}))
This topic is locked and can not be replied to.