Project

General

Profile

Actions

Bug #5940

closed

Resolve conflict between inheritance and mixins

Added by mlanza (Mario Lanza) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
1.9.2
Backport:
[ruby-core:42250]

Description

Some in the Ruby community (like Chad Fowler) have noticed issues around how Ruby attempts to transverse a method's pipeline up the inheritance chain. When you inherit a class from another class and then add a mixin, the mixin is not able to supercede the methods defined in the inherited-from class.

I've demonstrated the issue here:
https://gist.github.com/515856

It would be nice if Ruby were to change its default inheritance behavior so that mixin do override a class's methods. Essentially, the behavior would treat inheritance in nearly the same manner that it treats mixins.

class Person < ActiveRecord::Base
end

would be effectively treated, in a manner of speaking, as:

class Person
include ActiveRecord::Base
end

(I would go so far as to say that we get rid of direct inheritance in favor of always using mixins to accomplish our inheritance goals. I do have a reservation for how this would affect backwards compatibility.)

I dunno if Ruby's current behavior is intentional (having purposeful benefits) but I find it annoying as it makes it difficult to override a behavior in third-party libraries. When I own the classes, I can simply refactor them to prefer mixins as to avoid this issue, but this doesn't solve the dilemma when dealing with vendor libraries.

Actions

Also available in: Atom PDF