GEM and module? Could a GEM be a module?

Hello,

I have written a library that calculates dates based on CRON
specifications. I’d like to publish it as a GEM.

In order to avoid name collisions, I create a module (“Cron”) that holds
all the classes that build the library. In fact the is two classes :

Cron::Calendar
Cron::NoNextExecution

In your code, you write : c = Cron::CronCalendar.new(…)

As you may wish, the second class represents an exception that is raised
if it is not possible to find the date of the next execution (this may
occur if the CRON specification defines a range for the year). I
included this class within a module because the name of the class may be
used in another context (that is, in another GEM). For example, you
write a workflow processor… You may want to define an exception
“NoNextExecution”.

My question is :

Is it correct to say : “my GEM is a module” ?

Or should I “remove” the classes from the module ? (that is: no module
at all). But in this case, name collisions may occur.

Best regards,

Denis

On 29/05/2013, at 1:11 AM, Denis BEURIVE [email protected] wrote:

I have written a library that calculates dates based on CRON
specifications. I’d like to publish it as a GEM.

In order to avoid name collisions, I create a module (“Cron”) that holds
all the classes that build the library. In fact the is two classes :

Cron::Calendar
Cron::NoNextExecution

It is good practice to wrap your classes in a module. Lots of gems do
this.

Is it correct to say : “my GEM is a module” ?

Your gem is gem, it doesn’t matter if there is a module.

Henry

Thank you very much for these answers. I’ll keep the module in order to
avoid name collisions.

@Matthew K.

I did know this syntaxe. This is equivalent to the Perl’s one :

use moduleName (symbolToExport);

Best regards,

Denis

On Tue, May 28, 2013 at 8:11 AM, Denis BEURIVE [email protected]
wrote:

My question is :

Is it correct to say : “my GEM is a module” ?

No, that doesn’t really make sense. A gem is a way of organizing and
distributing code, a module is a type of Ruby object. You could say that
you distribute your module with a gem, but I can’t really think of a
situation where this phrase would come up. People are interested in what
the gem does “I have a gem that calculates dates based on the cron
specification” and how to use it “You say Cron::Calendar.new(...)” but
nobody really cares whether the namespace is a class or a module, and
typically aren’t even going to ask if it exists (though they’ll notice
if
it’s absent).

Or should I “remove” the classes from the module ? (that is: no module
at all). But in this case, name collisions may occur.

No, you should keep them namespaced, for the reasons you laid out.

-Josh

Henry M. wrote in post #1110429:

On 29/05/2013, at 1:11 AM, Denis BEURIVE [email protected] wrote:

I have written a library that calculates dates based on CRON
specifications. I’d like to publish it as a GEM.

In order to avoid name collisions, I create a module (“Cron”) that holds
all the classes that build the library. In fact the is two classes :

Cron::Calendar
Cron::NoNextExecution

It is good practice to wrap your classes in a module. Lots of gems do
this.

Agreed. If someone wants the Calendar and NoNextExecution classes in the
main namespace it’s trivial to do:

require ‘cron’
include Cron

But it’s impossible to do the inverse.

Is it correct to say : “my GEM is a module” ?

Your gem is gem, it doesn’t matter if there is a module.

You could say: “my gem defines a module …”