Created
January 11, 2011 06:17
-
-
Save hopsoft/774105 to your computer and use it in GitHub Desktop.
Monkeypatch - Illustrates how to re-open a class and redefine existing functionality
This file contains 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
# 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