From: Eric Hodel Date: 2006-07-15T02:34:36+09:00 Subject: Re: Preferred monkeypatching technique On Jul 14, 2006, at 10:24 AM, Tom Werner wrote: > 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 module X def does_something(*options) p options end end module Y def does_something(*options) super('x', *options) end end class C include X include Y end C.new.does_something 'foo' -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com