Project

General

Profile

Feature #1102

Prepend Module

Added by trans (Thomas Sawyer) over 11 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:21822]

Description

=begin
Currently when a module is included into a classes, it is appended to the class hierarchy (ie. the method lookup order). This of course makes sense, but there are times when it would be useful to prepend the module. For example:

class C
def x; "x"; end
end

module M
def x; '[' + super + ']'; end
end

class C
prepend M
end

C.new.x #=> "[x]"

One big advantage of this is being able to override methods in a safer way, rather than using alias or tricks like alias_method_chain.
=end


Related issues

Related to Ruby master - Feature #6452: Allow extend to override class methodsAssignedmatz (Yukihiro Matsumoto)05/19/2012Actions

Also available in: Atom PDF