Forum: Ruby Prevents multiple includes of the same module

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zouplaz (Guest)
on 2008-10-11 20:15
(Received via mailing list)
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
Thomas B. (Guest)
on 2008-10-11 21:39
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.
This topic is locked and can not be replied to.