The Case Against Monkey Patching, From a Rails Core Team Member (2023)

18-Aug-2023 823
If you’re new to Ruby, you might not be familiar with monkey patching because some other languages make it difficult to change the behavior of existing code. A monkey patch is code that dynamically alters the behavior of existing objects, typically ones outside of the current program. Often applications that have monkey patches are changing the behavior of the Rails framework or another gem, but I’ve also seen applications that monkey patch themselves which doesn’t quite make sense since monkey patches are global. When I say monkey patch, I mean something more broad than just extending an existing class. In my opinion, a monkey patch is any time you change the behavior of the underlying library in a surprising way. Let’s look at an open source example of this to get a better idea of what I mean.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle