From: Logan Capaldo Date: 2006-07-14T12:54:04+09:00 Subject: Re: Preferred monkeypatching technique On Jul 13, 2006, at 9:03 PM, Daniel DeLorme wrote: > Tom Werner wrote: >> Allow me to present a scenario: >> class Firetruck >> def put_out_fire(options = {}) >> # code >> end >> end > > Here's what I'd do to keep it clean: > > module FastFiretruck > def initialize(*args) > super > self.extend FastFiretruck::Obj > end > module Obj > def put_out_fire(options = {}) > super({:fast => "please!"}.merge(options)) > end > end > end > Firetruck.class_eval{ include FastFiretruck } > > Daniel > And I thought the blah = instance_method closure trick was cool, but this beats the pants off it. Note that you can use Firetruck.send(:include, FastFiretruck) or in 1.9 Firetruck.funcall(:include, FastFiretruck) to bypass the need for a block.