Created
May 20, 2011 18:15
-
-
Save ryanlecompte/983460 to your computer and use it in GitHub Desktop.
example of overriding a method in class via mixin
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 C | |
def initialize(*args) | |
puts "hi from C" | |
end | |
end | |
module M | |
def self.included(clazz) | |
clazz.class_eval do | |
alias_method :old_initialize, :initialize | |
def initialize(*args) | |
puts "hi from M" | |
old_initialize | |
end | |
end | |
end | |
end | |
class C | |
include M | |
end | |
C.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment