# Reopening a module vs. Module.include

**URL:** <https://www.ruby-forum.com/t/reopening-a-module-vs-module-include/66244>\
**Category:** Ruby\
**Created:** [August 24, 2006, 9:15am UTC](https://www.ruby-forum.com/t/reopening-a-module-vs-module-include/66244 "2006-08-24T09:15:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![markh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@markh](https://www.ruby-forum.com/u/markh)\
**Post date:** [August 24, 2006, 9:15am UTC](https://www.ruby-forum.com/t/reopening-a-module-vs-module-include/66244/1 "2006-08-24T09:15:25Z")

</div>

I am attempting to create a plugin, with some methods in my own module.  
These would then be included to various pieces of active record. This  
works  
fine when including them in classes, but when including them in a  
module,  
the classes which include that module do not get the methods. These  
classes  
do however get them when directly reopening the module. Is there any way  
around this, or is it best to just reopen the module and define the new  
methods?

Here is a stripped down example of the problematic code…

module A  
def test  
“test”  
end  
end

class B  
include A  
end

> > B.new.test  
> > =\> “test”

module C  
def test\_two  
“test\_two”  
end  
end

A.send :include, C

> > B.new.test\_two  
> > NoMethodError: undefined method `test\_two’ for #\<B:0xa7b8ddbc\>

class D  
include A  
end

> > D.new.test\_two  
> > =\> “test\_two”

HOWEVER…

module A  
def test\_two  
“test\_two\_again”  
end  
end

> > B.new.test\_two  
> > =\> “test\_two\_again”

---

<div class="post-metadata">

**Author:** ![markh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@markh](https://www.ruby-forum.com/u/markh)\
**Post date:** [August 24, 2006, 12:11pm UTC](https://www.ruby-forum.com/t/reopening-a-module-vs-module-include/66244/2 "2006-08-24T12:11:41Z")

</div>

Mark Van H. schrieb:

> I am attempting to create a plugin, with some methods in my own module.  
> These would then be included to various pieces of active record. This works  
> fine when including them in classes, but when including them in a module,  
> the classes which include that module do not get the methods. These classes  
> do however get them when directly reopening the module. Is there any way  
> around this, or is it best to just reopen the module and define the new  
> methods?  
> (…)

Mark, this is a known limitation of the current Ruby implementation. It  
has been discussed on the mailing lists. The only workaround I know is  
to re-include the module:

class B  
include A  
end

p B.new.test\_two # =\> “test\_two”

Regards,  
Pit
