Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Author Archives: Xavier Shay

By Xavier Shay / March 29, 2011

Monkey-patching is so 2010. We’re in the future, and with Github and Bundler there is now rarely a need to monkey-patch Ruby code in your applications.

Monkey-patching is the dangerous-yet-frequently-useful technique of re-opening existing classes to change or add to their behavior. For example, if I have always felt that Array should implement the sum method, I can add it in my codebase:

That is a monkey-patch. Of course, when I require activesupport it also adds a sum method to Array though its version has an arity of one and takes a block. This conflict can cause hard to track down errors and is why monkey-patching is to be used with caution. Read More