Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created January 11, 2011 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hopsoft/774105 to your computer and use it in GitHub Desktop.
Save hopsoft/774105 to your computer and use it in GitHub Desktop.
Monkeypatch - Illustrates how to re-open a class and redefine existing functionality
# define original class
class Example
def say_hello
puts "hello"
end
end
# re-open the class and monkeypatch some of its existing functionality
class Example
# re-define existing funnctionality
def say_hello
puts "hello from monkeypatch"
end
end
# usage
Example.new.say_hello # => hello from monkeypatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment