# Prevents multiple includes of the same module

**URL:** <https://www.ruby-forum.com/t/prevents-multiple-includes-of-the-same-module/150693>\
**Category:** Ruby\
**Created:** [October 11, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/prevents-multiple-includes-of-the-same-module/150693 "2008-10-11T18:15:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [October 11, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/prevents-multiple-includes-of-the-same-module/150693/1 "2008-10-11T18:15:26Z")

</div>

Hello, one module defines several CONSTANTS  
As it is required from few classes I get  
warning: already initialized constant FOO

How can I prevents the redefinition of theses CONSTANTS ? It’s just  
because it pollutes my screen during unit testing…

Thanks

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [October 11, 2008, 7:39pm UTC](https://www.ruby-forum.com/t/prevents-multiple-includes-of-the-same-module/150693/2 "2008-10-11T19:39:24Z")

</div>

Zouplaz wrote:

> Hello, one module defines several CONSTANTS  
> As it is required from few classes I get  
> warning: already initialized constant FOO
> 
> How can I prevents the redefinition of theses CONSTANTS ? It’s just  
> because it pollutes my screen during unit testing…
> 
> Thanks

It’s not clear what’s your problem. If you do this:

module M;A=8;end  
class K;include M;end  
class L;include M;end

you get no warning as the constants is not redefined by including the  
module. It just becomes accessible as K::A and L::A. I think you should  
paste an isolated sample to illustrate your problem.

TPR.
