# Un-include?

**URL:** <https://www.ruby-forum.com/t/un-include/86259>\
**Category:** Ruby\
**Created:** [February 21, 2007, 12:16am UTC](https://www.ruby-forum.com/t/un-include/86259 "2007-02-21T00:16:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [February 21, 2007, 12:16am UTC](https://www.ruby-forum.com/t/un-include/86259/1 "2007-02-21T00:16:24Z")

</div>

I have this object which has “include” declared. I want to, in certain  
situations, not have the include happen. I can turn it off with an  
“if” or an “unless”, but is there any way to actually just yank the  
include out, and with it any changes it made to the thing which  
included it?

(I’m almost certain the answer’s no but it’d be pretty cool if I was  
wrong.)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [February 22, 2007, 9:37am UTC](https://www.ruby-forum.com/t/un-include/86259/2 "2007-02-22T09:37:53Z")

</div>

Wow, that does sound evil. I’m actually thinking the whole thing can  
be side-stepped. The module uses included to add methods to an object;  
it may be cleaner just to write something which adds methods to  
instances of the object as needed instead.

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [February 22, 2007, 7:48am UTC](https://www.ruby-forum.com/t/un-include/86259/3 "2007-02-22T07:48:39Z")

</div>

Giles B. schrieb:

> I have this object which has “include” declared. I want to, in certain  
> situations, not have the include happen. I can turn it off with an  
> “if” or an “unless”, but is there any way to actually just yank the  
> include out, and with it any changes it made to the thing which  
> included it?

Giles, it depends on what you’re willing to pay 🙂

If you can change the code doing the “include”, there are libraries like  
import-module (see the RAA) which let you do what you want.

If you can’t or don’t want to change the code with the “include”, I see  
no other way than to directly access the internal structures of the Ruby  
objects. This can be done using a little C extension, or with plain Ruby  
code using techniques from the evil library (see RubyForge).

If you want to go one of these routes and need more info, please ask  
again.

Regards,  
Pit
