Created
October 28, 2010 07:05
-
-
Save sj26/650811 to your computer and use it in GitHub Desktop.
MRO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def initialize | |
puts "A initialized" | |
end | |
end | |
module B | |
def initialize_with_b | |
puts "B initialized" | |
end | |
end | |
A.send :include, B | |
A.new | |
# => "A initialized" | |
module C | |
def initialize_with_c | |
puts "C initialized" | |
initialize_without_c | |
end | |
def self.included(base) | |
base.class_eval do | |
alias :initialize_without_c :initialize | |
alias :initialize :initialize_with_c | |
# or: alias_method_chain :initialize, :c | |
end | |
end | |
end | |
A.send :include, C | |
A.new | |
# => "C initialized" | |
# => "A initialized" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment