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

Shin guey Wong wrote:
| Julian Leviston wrote:
|> A module is simply a place where you can store methods.
|>
|> Thus, you can include a module as a mixin in a class, and it will get
|> all the methods.
|>
|
| Yes, but we can achieve the same thing by inherit a class which will get
| all the methods also.I know we can mixin multiple classes but only
| inherit 1 class.
| If there is only 1 class/module, which we should use? create a module or
| class?

Yes. :P

It depends, actually. A module provides a namespace, and (ideally)
prevents namespace collisions.

It also provides grouping of classes (well, d'uh. I'm amazed at my
insightfulness at this early hour..).


Let's say you have an application, which brings its own String, Math,
and Array functions. If you put them into the Module MyApplication, you
prevent collisions with Ruby's String, Math, and Array functions.

Additionally, you can mixin these methods, while maintaining the ability
to inherit from the classes you have in your modules, if need be.

(You can inherit from Digest::MD5, for example.)

Also, only a module can include a module.

In short: It depends on your scenario.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

Make the coupling between modules visible.
~            - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf8WtgACgkQbtAgaoJTgL8CZACgk0bY83eL9DX8JZExeXfBJfs+
xpkAnibP1+clUdU5ii7Dzv1UAvZPLzL6
=5zTq
-----END PGP SIGNATURE-----