Project

General

Profile

Actions

Feature #7519

closed

Module Single Inheritance

Added by trans (Thomas Sawyer) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:50580]

Description

A limitation of modules is that they can not gain and augment the qualities of another module in the same manner that a class can of another class. They can use #include, but using #include to carry the behavior of one module into another is limited in that singleton methods are not available to it and also because of the well known Module Include Problem. So it occurs to me that modules could have their own inheritance chain.

For example:

module M
def self.foo
"foo"
end
def bar
"bar"
end
end

module N < M
def bar
super + "!"
end
end

N.foo #=> "foo"

class C
include N
end

C.new.bar #=> "bar!"

I think it easy to think about in terms of classes being types of "nouns", and modules being types of "adjectives". So just as one "noun" can inherit the behavior of another "noun", so could one "adjective" inherit the behavior of another "adjective".

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0