How-to unmixin a module

Hi,

How do you undo the mixing in of a module? Is it possible? I guess
you would have to save the state (current methods) of the class before
the mixin, then iterate through the methods and class variables of the
module, remove or undefined each one, then re-mixin or re-define the
previous state of the class before the mixin. Does that sound right?
Is there an easier way?

Thanks,
David :slight_smile:

On Sun, Mar 30, 2008 at 5:44 AM, David B.
[email protected] wrote:

Hi,

How do you undo the mixing in of a module? Is it possible? I guess
you would have to save the state (current methods) of the class before
the mixin, then iterate through the methods and class variables of the
module, remove or undefined each one, then re-mixin or re-define the
previous state of the class before the mixin. Does that sound right?
Absolutely.
Is there an easier way?
I do not think so.

Thanks,
David :slight_smile:

Cheers
Robert

Posted via http://www.ruby-forum.com/.

โ€“
http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

I had just an idea about your problem, this is of course a fake
solution, but maybe it is helpful.
If you can live with the warning or if you can avoid to use constants
for classes you could always save a copy of the class before including
the module and than โ€œunincludeโ€ the module by restoring it, of course
this means that all other potential operations on the original class
will be lost too :frowning:

module Outer
module N
def a; 222 end
end
module M
def a; 42 end
def b; 101010 end
end

class C
include N
end
copie = C.clone
class C
include M
end

puts C.new.a
puts C.new.b
const_set โ€œCโ€, copie
puts C.new.a
puts C.new.b
end

Cheers
Robert

http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein