Skip to content

Instantly share code, notes, and snippets.

@Timrael
Created June 18, 2012 06:28
Show Gist options
  • Save Timrael/2947135 to your computer and use it in GitHub Desktop.
Save Timrael/2947135 to your computer and use it in GitHub Desktop.
Monkey Patching
class Foo
def bar
puts "Hello, world!"
end
end
module Monkey
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method :bar, :meow
end
end
module InstanceMethods
def meow
puts "Meow!!"
end
end
end
Foo.new.bar # => "Hello, world!"
Foo.send(:include, Monkey)
Foo.new.bar # => "Meow!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment