Project

General

Profile

Bug #11301

Module#prepend should have always added the module before the current

Added by matz (Yukihiro Matsumoto) about 4 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:69722]

Description

I don't think it's ideal:

module M
end  

class A
  prepend M
end  

A.ancestors
# => [M, A, Object, PP::ObjectMixin, Kernel, BasicObject]

class B<A
  prepend M
end  
B.ancestors
# => [B, M, A, Object, PP::ObjectMixin, Kernel, BasicObject]

It should be either error (for not adding module) or the module appearing multiple times,
i.e. B.ancestors to be

[M, B, M, A, Object, PP::ObjectMixin, Kernel, BasicObject]

Matz.

History

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Description updated (diff)

I think we have tried it some times but not made a conclusion.

Change Module#prepend only?

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

  • Status changed from Open to Closed

This was fixed between Ruby 2.2 and Ruby 2.3:

$ ruby23 -e "module M; end; class A; prepend M; end; class B<A; prepend M; end; p B.ancestors"
[M, B, M, A, Object, Kernel, BasicObject]
$ ruby22 -e "module M; end; class A; prepend M; end; class B<A; prepend M; end; p B.ancestors"
[B, M, A, Object, Kernel, BasicObject]

Also available in: Atom PDF