Issue #17423 has been updated by jeremyevans0 (Jeremy Evans).


Based on the decision made at the developer meeting (https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20210113Japan.md#bug-17423-prepend-should-prepend-a-module-before-the-class-jeremyevans0), I've added a pull request that will make Module#prepend insert a module in the ancestor chain even if the receiver already includes the module: https://github.com/ruby/ruby/pull/4072

----------------------------------------
Bug #17423: `Prepend` should prepend a module before the class
https://bugs.ruby-lang.org/issues/17423#change-89954

* Author: matz (Yukihiro Matsumoto)
* Status: Open
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I see

```ruby
module M; end
module A; end
class B; include A; end

A.prepend M
B.prepend M
p B.ancestors
```

gives `[B, M, A, Object, Kernel, BasicObject]` now. It used to be `[M, B, A, Object, Kernel, BasicObject]`.

I think it should be prepended to class `B`. Probably it should be `[M, B, M, A, Object, Kernel, BasicObject]`.

The reason behind this change may be duplication removing, but considering the following code, it is OK to duplicate prepende modules.

```ruby
module M; end
class A; end
class B<A; end

A.prepend M
B.prepend M
p B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Am I missing something?

Matz.






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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>