Hi all,

I'm currently drowning in a pool of instance_methods and define_methods
and I can't seem to get out. I know there's an elegant solution
somewhere....

I have a Class object klass. It has an instance method meth(). I'd like
to "extend" meth() so that when it's called, the output is changed---I
want to call the original meth(), tweak its result, and then return it.
I need to return a Class object that has this tweak in place; I can
either change klass and return that or I can subclass it and return the
subclass.

Something like:

def tweaked_class(klass)
  old_meth = klass.instance_method(:to_html)
  klass.define_method(:meth) do |*a|
    r = old_meth(*a)
    # ... transform r ...
    r
  end
  klass
end

But that doesn't work, and I might be on the wrong track completely.
So what's the best way to do this?

Thanks,

-- 
William <wmorgan-ruby-talk / masanjin.net>