From: ruby-core@... Date: 2017-11-29T16:30:02+00:00 Subject: [ruby-core:83975] [Ruby trunk Feature#1586] Including a module already present in ancestors should not be ignored Issue #1586 has been updated by marcandre (Marc-Andre Lafortune). Thank you for the consideration. May I add two observations? 1) `prepend` had similar behavior (ignoring already prepended modules) in 2.0 and 2.1. It was changed in 2.2 and I don't remember incompatibility problems. 2) If incompatibility is actually an issue, could we detect cases where we ignore wrongly an include and issue a warning, and make the changes in the next version? ---------------------------------------- Feature #1586: Including a module already present in ancestors should not be ignored https://bugs.ruby-lang.org/issues/1586#change-68055 * Author: bitsweat (Jeremy Daer) * Status: Rejected * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * 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, #, Precision, Numeric, Foo, Comparable, Object, Kernel] =end ---Files-------------------------------- inclusion.pdf (56.4 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: