Project

General

Profile

Actions

Bug #8052

closed

"prepend Mod1, Mod2" behaves strangely

Added by gcao (Guoliang Cao) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
Backport:
[ruby-core:53240]

Description

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
}))

Updated by marcandre (Marc-Andre Lafortune) about 11 years ago

  • 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).

Updated by gcao (Guoliang Cao) about 11 years ago

My bad :-D

I was so excited that I found a bug in Ruby... just kidding.

Actions

Also available in: Atom PDF

Like0
Like0Like0