On Apr 7, 4:27 am, Jed <[email protected]> wrote:
> It wasn't clear from the examples whether a module is a collection of
> related classes, like a package, or if they are a series of methods,
> like helpers, that are used by a class but not structured (similar to
> the include keyword in actionscript or java). Or maybe something
> totally unrelated to the above mentioned concepts. What is the best
> definition?
I guess you will not be pleased with my answer, as you'll discover
soon that in ruby there is rarely best usage, nor best definition.

Depending on how you use it, I would say both, but with a big
difference in the sense that you cannot instantiate a module.
So it could be a way to group methods, constants, and class variables
in a namespace (the name of the module). This form is used when you
don't need to instantiate an object.
As you can nest modules, and classes are a form of modules, you may
also define classes inside a module, and consequently instantiate an
object of those classes.

The second usage is the mixin, when you include the module inside a
class,  it can be viewed as helper, generic, or kind of semi-interface
in this case. As examples of mixins, you may see Enumerable and
Comparable.

Another example which makes usage of both alternatives (include and
namespace), see the Math and the Kernel modules.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to