Un_extend - dynamic mix-out?

I know that I can do obj.extend(Mod) to dynamically mixin a module.
But how can I get rid of this module and replace it with something else?
Is there a way of effectively doing un_extend(Mod); extend(Mod2)?
I want to program agents that can adapt their behaviour to the situation
or context they find themselves in, i.e. context-dependent behaviours.

#A simple example of something I’d like to be able to do:
class IPD_Agent
def initialize(strategy)
@strategy = Object.const_get(strategy)
extend(@strategy)
end
def change_strategy(strategy)
#this is the command I want
un_extend(@strategy)
@strategy = Object.const_get(strategy)
extend(@strategy)
end
end
#Tft, AllC and AllD are different behaviour modules
agent = IPD_Agent.new(:Tft)
agent.change_strategy(:AllC)
agent.change_strategy(:AllD)

I’m currently doing effectively this via Delegation, which works quite well.
There might be other ways of doing this that don’t require un_extend.

I specifically want to know though whether there is some hidden way to
un_extend a dynamically added module from an object, or at least to find
reliably which methods have been dynamically added to an object (i.e. to its
special singleton class) and remove those (but not, for instance, stopping the
object from responding to each or to_s if they have been dynamically
redefined).

Matt

Is there a way of effectively doing un_extend(Mod); extend(Mod2)?

Well, see [ruby-talk:39234] to find where is the problem

http://www.ruby-talk.org/39234

Guy Decoux