Created
May 16, 2012 17:29
-
-
Save e0da/2712425 to your computer and use it in GitHub Desktop.
demo monkey patching
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
word = 'potato' | |
puts word.yell # NoMethodError | |
class ::String | |
def yell | |
"HEY! #{self.upcase}!" | |
end | |
end | |
puts word.yell # HEY! POTATO! | |
module Stupid | |
class Server | |
def start | |
@process = get_new_server_process | |
nil | |
end | |
def stop | |
@process.stop | |
nil | |
end | |
end | |
end | |
server = Stupid::Server.start | |
server.stop # too slow... won't stop... can't kill it | |
server.process # NoMethodError. don't have access to that | |
module Stupid | |
class Server | |
def kill | |
@process.kill | |
end | |
end | |
end | |
server.kill # there we go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment