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.
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.