Saturday, September 08, 2012

Boobytrap your Monkey Patches!

If you are going to override an entire method with a monkey patch, at least do this:

raise "Make sure I'm still required!" unless Gem.loaded_specs["GEM_NAME"].version.to_s == "VERSION_THAT_REQUIRED_PATCH"

somewhere inside the file that does the monkey patching. Consider it a courtesy for everyone else, including yourself.

...

Okay, so I spent about 7 hours fiddle-fucking around with an inexplicable circumstance that came down to someone monkey patching an entire goddamn class by copying and pasting the Git HEAD version of that class so that an older version of the gem could use some of the newer version's functionality. Of course, 10 months later the underlying gem got upgraded way past the version the monkey patch came from, so a whole subset of functionality just broke "like magic!"

No comments: