From: shyouhei@... Date: 2017-11-30T00:53:12+00:00 Subject: [ruby-core:83989] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain Issue #12834 has been updated by shyouhei (Shyouhei Urabe). marcandre (Marc-Andre Lafortune) wrote: > Could you clarify? > > For inclusion/prepending, there are two questions in my mind: > 1) what happens if a module is included/prepended multiple times at different places in the hierarchy (e.g. in A and B, in the example above) > 2) what happens if it is included/prepended multiple times at the same level (e.g. twice in A) > > Was the discussion about (b) allowing multiple times at the same level? I don't remember there were discussions about inclusion in this topic. There were ones for prepending only. From what I understand the intention of prepending a module more than once is: #### `1)`'s situation: #### ```ruby module X def x; "X<%s>" % super end end module Y prepend ::X; def x; "Y<%s>" % super end end module Z prepend ::Y; def x; "Z<%s>" % super end end class W prepend ::X prepend ::Z def x 'W' end end W.new.x # => "X>>>" ``` #### `2)`'s situation: #### ```ruby module X def x; "X<%s>" % super end end module Y prepend ::X; def x; "Y<%s>" % super end end module Z prepend ::X; def x; "Z<%s>" % super end end class W prepend ::Y prepend ::Z def x 'W' end end W.new.x # => "X>>>" ``` Note: current trunk does not behave this way. ---------------------------------------- Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain https://bugs.ruby-lang.org/issues/12834#change-68068 * Author: ndn (Nikola Nenkov) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3.1 * Backport: 2.3: UNKNOWN ---------------------------------------- ``` module M; end class A; prepend M; end class B < A; prepend M; end B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject] ``` Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking. I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. -- https://bugs.ruby-lang.org/ Unsubscribe: