Skip to content

Instantly share code, notes, and snippets.

@e0da
Created May 16, 2012 17:29
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 e0da/2712425 to your computer and use it in GitHub Desktop.
Save e0da/2712425 to your computer and use it in GitHub Desktop.
demo monkey patching
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