Project

General

Profile

Actions

Feature #1586

closed

Including a module already present in ancestors should not be ignored

Added by bitsweat (Jeremy Daer) almost 15 years ago. Updated over 6 years ago.

Status:
Rejected
Target version:
[ruby-core:23740]

Description

=begin
The scenario:

  • I include Foo in Numeric to provide #bar
  • Some other library includes a module in Float to provide #bar
  • So I include Foo in Float to use my #bar
  • But including Foo in Float is ignored since it's already in the ancestor chain

I think it should be added to the ancestor chain, even if it's already present, since I may want to override some other method earlier in the ancestor chain.

Including a module already included in a superclass is ignored

module Foo; end
=> nil
class Numeric; include Foo; end
=> Numeric
Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
class Float; include Foo; end
=> Float
Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]

Reversing the order of inclusion works as expected

module Foo; end
=> nil
class Float; include Foo; end
=> Float
Float.ancestors
=> [Float, Foo, Precision, Numeric, Comparable, Object, Kernel]
class Numeric; include Foo; end
=> Numeric
Float.ancestors
=> [Float, Foo, Precision, Numeric, Foo, Comparable, Object, Kernel]

And so does including a dupe of the existing module in the subclass

module Foo; end
=> nil
class Numeric; include Foo; end
=> Numeric
Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
class Float; include Foo.dup; end
=> Float
Float.ancestors
=> [Float, #Module:0x19bcd40, Precision, Numeric, Foo, Comparable, Object, Kernel]
=end


Files

inclusion.pdf (56.4 KB) inclusion.pdf claytrump (Clay Trump), 07/01/2012 08:53 AM

Related issues 4 (0 open4 closed)

Related to Ruby master - Bug #5236: Including a module in a superclass after it has been included in a subclass leads to infinite recursion if the module uses `super`Closednobu (Nobuyoshi Nakada)08/27/2011Actions
Related to Ruby master - Bug #3351: stack overflow on superClosedko1 (Koichi Sasada)Actions
Related to Ruby master - Feature #9112: Make module lookup more dynamic (Including modules into a module after it has already been included)Closedmatz (Yukihiro Matsumoto)Actions
Has duplicate Ruby master - Bug #8066: Inconsistency in ancestors chainRejected03/10/2013Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0