Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created May 20, 2011 18:15
Show Gist options
  • Save ryanlecompte/983460 to your computer and use it in GitHub Desktop.
Save ryanlecompte/983460 to your computer and use it in GitHub Desktop.
example of overriding a method in class via mixin
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