I find IRB extremely useful as a tool for trial and error style debugging, where I don’t really know where a problem is coming from, but can take advantage of the REPL nature of IRB to quickly iterate through a list of potential ways to reproduce an issue and distill it down.
Occasionally I decide to re-open a class belonging to a loaded gem and add some debug output to a method, or override the method entirely. Once that is done, is there an easy to way “un-monkey patch” the class, without quitting IRB and restarting it (my current approach)?
If you’re redefining a method, you could create and
aliasfor the old method and then define your new one. When you’re done, you could redefine the method yet again and call the method alias.Step one:
When you’re done: