Skip to content

Instantly share code, notes, and snippets.

@sj26
Created October 28, 2010 07:05
Show Gist options
  • Save sj26/650811 to your computer and use it in GitHub Desktop.
Save sj26/650811 to your computer and use it in GitHub Desktop.
MRO
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