# Classes within a module?

**URL:** <https://www.ruby-forum.com/t/classes-within-a-module/105316>\
**Category:** Ruby\
**Created:** [May 28, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/classes-within-a-module/105316 "2007-05-28T19:35:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 28, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/classes-within-a-module/105316/1 "2007-05-28T19:35:53Z")

</div>

Why do Rubyists generally hold a number of classes within a module?

cheers

aidy

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 28, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/classes-within-a-module/105316/2 "2007-05-28T19:43:53Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Say you had a class called “Document”, there is already a class called  
“Document”, so you need to differentiate between the two, so you put  
them in  
separate modules. So then “MODULE1::Document” is different from  
“MODULE2::Document”.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFGWxSW2vy7v+d+psQRAiyuAJ9Hy9kkpx6+vM0EqOWItOiB6ygbfgCgugzL  
tmtWlXNCbQF1O2qBCAFaA28=  
=jlYr  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 28, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/classes-within-a-module/105316/3 "2007-05-28T19:45:54Z")

</div>

On May 28, 10:31 am, “removed\_email\_address@domain.invalid”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Why do Rubyists generally hold a number of classes within a module?

If you’re working on a library to do X, and I’m working on a library  
to do Y, and someone else wants to use both libraries in his  
application; if we each put our code inside XStuff and YStuff,  
respectively, then he won’t have to worry about whether we both use a  
class named Foo for unrelated purposes. Otherwise, the open classes in  
ruby would mean that one definition might trounce parts of another and  
neither one would likely work correctly except by luck.

There are other reasons for putting classes in a module, but this is  
likely the main one. (Although there are other uses for modules as  
well – especially for use as mixins).

–  
Regards,

John W.
