Forum: Ruby classes within a module?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee6788c2faaad7a5cd0bc466c9ea60d8?d=identicon&s=25 (Guest)
on 2007-05-28 19:35
(Received via mailing list)
Why do Rubyists generally hold a number of classes within a module?


Ef53c4abeae8cc46327030bae489a33c?d=identicon&s=25 Fred Phillips (Guest)
on 2007-05-28 19:43
(Received via mailing list)
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
Version: GnuPG v1.4.3 (GNU/Linux)

10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 John Wilger (jwilger)
on 2007-05-28 19:45
(Received via mailing list)
On May 28, 10:31 am, ""
<> 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).


John Wilger
This topic is locked and can not be replied to.