Created
June 18, 2012 06:38
MonkeyPatching
This file contains hidden or 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 Foo | |
def self.bar | |
puts "Hello, world!" | |
end | |
end | |
module Monkey | |
def self.included(base) | |
base.extend(ClassMethods) | |
base.class_eval do | |
class << self | |
alias_method :bar, :meow | |
end | |
end | |
end | |
module ClassMethods | |
def meow | |
puts "Meow!!" | |
end | |
end | |
end | |
Foo.bar # => "Hello, world!" | |
Foo.send(:include, Monkey) | |
Foo.bar # => "Meow!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment