Forum: Ruby Good practices when writing modules.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2ec38e324983babdd5c926c56f9e0c80?d=identicon&s=25 Alex Polite (Guest)
on 2006-05-24 18:01
(Received via mailing list)
Hi.

My learning-ruby-playground-project has gotten to the point where I
feel the need to split the source into several files. Coming from
python and java I'm both delighted and horrified to realize that file
names do not need to correspond to module names or class names.

I'd like to read something on good practices when writing ruby
modules. Are there any conventions that most writers adhere to? What's
the equivalent of PYTHONPATH and JAVAHOME? What do I need to do in
order for my modules to be available without specifying the full path?
I'm looking for reading material dealing with these sort of questions.
Anything available online receives a bonus ;)

TIA Alex
567898c496278341be69087507d5ed24?d=identicon&s=25 Jeff Rose (Guest)
on 2006-05-24 18:50
(Received via mailing list)
Alex Polite wrote:
> order for my modules to be available without specifying the full path?
> I'm looking for reading material dealing with these sort of questions.
> Anything available online receives a bonus ;)
>
> TIA Alex

I don't know of a specific resource, but I can help with a few things...

RUBYLIB - search path for programs
RUBYOPT - extra command line args

files are typically lower case with underscores, and when you require
you don't use the '.rb' suffix.  The global variable $: is an array that
holds the current load path, and you can add to it at runtime if you
want to make other directories available for requiring.  (Rather than
putting the whole path in for each require.)

Typically you will see this at the top of unit tests that are testing a
library with a typical directory structure: (root/test, root/lib)

$:.unshift(File.dirname(__FILE__) + '/../lib')

The unshift method just puts it at the front of the list, which I think
is done in case there might be a collision with something already
installed.

Hope this helps,

-Jeff
This topic is locked and can not be replied to.