how-to unmixin a module

D

David Beckwith

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 :)
 
R

Robert Dober

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 :)
 
R

Robert Dober

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 :(

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top