From: Matthew Kerwin Date: 2013-05-11T08:33:23+09:00 Subject: Re: What is module in Ruby? Is there any standard (any strict rules) to define module? --e89a8f643564aa062b04dc65970e Content-Type: text/plain; charset=ISO-8859-1 On May 11, 2013 5:19 AM, "Wins Lin" wrote: > > 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? 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. --e89a8f643564aa062b04dc65970e Content-Type: text/html; charset=ISO-8859-1

On May 11, 2013 5:19 AM, "Wins Lin" <lists@ruby-forum.com> wrote:
>
> 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?

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.

--e89a8f643564aa062b04dc65970e--