What is a module in Ruby? Is there any standard (any strict rules) to define module?

What is a module in Ruby?

For now I can’t see any standard that could help me to define a module.

They say that “a module == a directory”. But that’s not true.
In Rails they define modules just as they want. Some are bound with a
directory with the same name, others are just plain files.

E.g. in ActiveRecord there is a line:

autoload :SessionStore

So session_store has to be:

  1. a module
  2. a directory with the same name (/session_store/*)

But session_store is:

  1. a class
  2. and a simple file, no any directory.

And there are many more similar examples.

So where is the standard of module definition in Ruby? What are the
rules?

On Fri, May 10, 2013 at 2:15 PM, Wins L. [email protected] wrote:

So where is the standard of module definition in Ruby? What are the
rules?


Posted via http://www.ruby-forum.com/.

In Ruby, very simply, a Module defines a scope and a namespace. But
that is hugely simplistic. I highly recommend reading “Metaprogramming
Ruby” for some real insight on this, as well as the good old pickaxe
book.

There are many fine additional references at the end of

On May 11, 2013 5:19 AM, “Wins L.” [email protected] wrote:

autoload :SessionStore

So where is the standard of module definition in Ruby? What are the
rules?

Just an aside: a filesystem directory is one type of directory, but not
all
dirctories are filesystem directories.

In the general sense, a directory is a searchable list of the names of
things and references to the things themselves (or “directions” on how
to
access them).

E.g. a map of filename => inode, or name => phone number, or symbol =>
function.

As has been mentioned elsewhere, a module is an object that holds
functions. You can use it to group related functions, and refer to them
in
a meaningful way, such as the ‘Math’ object in javascript.

You can also use modules to define or call functions with the same name
as
other/existing fucctions without creating ambiguity (namespacing).

Also, you can “mix” a module into a class, so that object instances of
that
class inherit the funtions as methods.

Sent from my phone, so excuse the typos.