monkeypatching

How to Monkey Patch in Ruby on Rails?

Lets use a real world example. I want to monkey patch WillPaginate::LinkRenderer.to_html method. So far I have tried: Created a file in folder: lib/monkeys/will_paginate_nohtml.rb Added in config/environments.rb: require 'monkeys/will_paginate_nohtml' at the end of the file Inside that file, this was my code: e module Monkeys::W...

How do I monkey-patch ruby's URI.parse method

Some popular blog sites typically use square brackets in their URLs but ruby's built-in URI.parse() method chokes on them, raising a nasty exception, as per: http://redmine.ruby-lang.org/issues/show/1466 I'm trying to write a simple monkey-patch that gracefully handles URLs with the square bracket. The following is what I have so far: ...

Monkey patching a Django form class?

Given a form class (somewhere deep in your giant Django app).. class ContactForm(forms.Form): name = ... surname = ... And considering you want to add another field to this form without extending or modifying the form class itself, why does not the following approach work? ContactForm.another_field = forms.CharField(...) (...