Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
how-to unmixin a module
David Beckwith
3/30/2008 3:45:00 AM
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 :)
--
Posted via
http://www.ruby-...
.
2 Answers
Robert Dober
3/30/2008 5:21:00 PM
0
On Sun, Mar 30, 2008 at 5:44 AM, David Beckwith <dbitsolutions@gmail.com> 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 :)
> --
Cheers
Robert
> Posted via
http://www.ruby-...
.
>
>
--
http://ruby-smalltalk.blo...
---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein
Robert Dober
3/31/2008 12:52:00 PM
0
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
--
http://ruby-smalltalk.blo...
---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
how-to unmixin a module
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password