# How-to unmixin a module

**URL:** <https://www.ruby-forum.com/t/how-to-unmixin-a-module/133321>\
**Category:** Ruby\
**Created:** [March 30, 2008, 5:44am UTC](https://www.ruby-forum.com/t/how-to-unmixin-a-module/133321 "2008-03-30T05:44:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 30, 2008, 5:44am UTC](https://www.ruby-forum.com/t/how-to-unmixin-a-module/133321/1 "2008-03-30T05:44:41Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 30, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/how-to-unmixin-a-module/133321/2 "2008-03-30T19:21:53Z")

</div>

On Sun, Mar 30, 2008 at 5:44 AM, David B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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://www.ruby-forum.com/).

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

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

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 31, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/how-to-unmixin-a-module/133321/3 "2008-03-31T14:53:36Z")

</div>

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.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

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