From: _z Date: 2001-01-16T13:10:02+09:00 Subject: [ruby-talk:9361] Re: Packages within Ruby I am new to Ruby (so if my suggestion isn't good - please pardon). setting RUBYLIB (env variable) to include the gplot directory should eliminate the need to specify gplot as part of require. Alternately (not a clean thing) adding the gplot directory to $: array within the program should also accomplish the same. Gordon Miller wrote in message news:m3itngqku4.fsf@cj47640-b.dlcty1.va.home.com... > I am working on a wrapper around Gnuplot that involves a large number of > classes and a good amount of code. Keeping all of the code in one file is > just confusing and really violates my anal retentive sense of order that I > like to keep my code in. In Python, which is where I have spent the bulk of > my past few scripting years, there is the concept of a package. With this, if > you import a directory name, python will look for a __init__.py file in the > directory of that name. This file typically contains other import statements > to include the files of the package. I was thinking that it would be nice to > duplicate this kind of functionality within ruby. > > What I've decided to do in the short term is to create the directory and then > in that directory put the files that constitute the package. From this file, > I then require the other files. For example: > > gplot (directory) > Gnuplot.rb > Stream.rb > PlotItem.rb > > Where Gnuplot.rb contains the following lines > > require 'gplot/Stream' > require 'gplot/PlotItem' > > This seems to be working fine, but my primary beefs with this that I have to > include the gplot as part of the require path and in my client code I have to > write require 'gplot/Gnuplot' instead of require 'gplot' which is what I > really want. > > Any suggestions, comments, or flames? > > -- > Gordon James Miller > gmiller@bittwiddlers.com