Issue #1586 has been updated by marcandre (Marc-Andre Lafortune).


matz (Yukihiro Matsumoto) wrote:
> When I made this change in early 1.9, it caused huge incompatibility.
> I had to fix many bundled programs.  So it shouldn't be a minor change.

When you did this, was it possible to include a module more than once for the same class, or simply possible once for any class/module, even when it present somewhere else in the ancestor chain? (See http://bugs.ruby-lang.org/issues/1586#note-16 for an example)

I believe that allowing inclusion of a module once per module is the most useful and would not cause incompatibility.

----------------------------------------
Feature #1586: Including a module already present in ancestors should not be ignored
https://bugs.ruby-lang.org/issues/1586#change-34432

Author: bitsweat (Jeremy Kemper)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: Next Major


=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



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