PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > how-to unmixin a module
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
how-to unmixin a module

Réponse
 
LinkBack Outils de la discussion
Vieux 30/03/2008, 04h44   #1
David Beckwith
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 30/03/2008, 18h20   #2
Robert Dober
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how-to unmixin a module

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-forum.com/.
>
>




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

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

  Réponse avec citation
Vieux 31/03/2008, 13h52   #3
Robert Dober
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how-to unmixin a module

I had just an idea about your problem, this is of course a fake
solution, but maybe it is ful.
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.blogspot.com/

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10810 seconds with 11 queries