From: Tom Werner Date: 2006-07-15T02:24:36+09:00 Subject: Re: Preferred monkeypatching technique Eric Hodel wrote: > On Jul 13, 2006, at 5:04 PM, Tom Werner wrote: > >> Eric Hodel wrote: >>> You just described subclasses: >> >> Well, the idea is that the 3rd party software is going to be using >> whatever classes it has always used, so just creating a subclass >> doesn't get me anywhere because the 3rd party app (i.e. Rails) >> doesn't give a hoot about my BigNozzleFiretruck. > > Can you give a concrete example where this takes place? > My specific purpose is to write a plugin for Rails that adds an option to each form field helper (the ones that create tags) that specifies an appropriate class (since CSS attribute selector support is lacking in IE). So I'm using code like this: module ActionView module Helpers module FormHelper # text alias_method :__classless_text_field, :text_field def text_field(object_name, method, options = {}) __classless_text_field(object_name, method, options.merge({:class => (options[:class].to_s + ' text').strip})) end end end end Which works fine, but is subject to the infinite loop problem should someone else happen to alias in an identical manner. Even the *possibility* of this happening makes me feel dirty, and so I'm looking for a cleaner way to do it. As these helpers may be called quite often, a solution that doesn't badly impact performance is essential. There are some other ideas on this thread that I still need to investigate, I was just curious if there's some standard practice for this sort of thing. Thanks!! Tom -- Tom Werner Helmets to Hardhats Software Developer tom@helmetstohardhats.org www.helmetstohardhats.org