Patching monkeys is not considered bad practice unless you write odd methods that don't have PatchedClass-related behavior (e.g. String.monkeyPatchForMakingJpegFromString pretty bad, but Jpeg.fromString is good enough.)
But if your project is large enough, the libraries that you use in it may have counter corrections, so you may have another problem with all these patch files. In Ruby 2.0, refinements come to the rescue. They work as follows: you define a module , refine your (even core) class in it, and then use this module where necessary. So in your code, it works like:
YourClass.new.refinedMethodFromCoreClass
But
CoreClass.refinedMethodFromCoreClass
undefined method exception.
What all corrections for monkeys: the monkey patch is useful and convenient, but refinements add some functions that make your code more secure, convenient and accurate.
source share