Skip to content

Instantly share code, notes, and snippets.

@Timrael
Created June 18, 2012 06:38
Show Gist options
  • Save Timrael/2947172 to your computer and use it in GitHub Desktop.
Save Timrael/2947172 to your computer and use it in GitHub Desktop.
MonkeyPatching
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