From: Joel VanderWerf Date: 2005-07-23T01:35:29+09:00 Subject: Re: Are there packages? James Edward Gray II wrote: > On Jul 22, 2005, at 7:48 AM, Brian Candler wrote: > >> Note 3: if you want to run the programs in bin/ without first installing >> their libraries you can do so, but you'll need to update the $LOAD_PATH >> appropriately. This can be done by hand: >> >> cd bin >> ruby -I../lib my_program.rb >> >> or in the outer directory: >> >> ruby -Ilib bin/my_program.rb > > > It's often desirable to add both directories to the path, especially > with testing (Test Suites load Test Cases probably in the same > directory). The -I option can handle this too: > > ruby -I lib:test test/ts_all.rb > >> If anybody has a simpler solution than this, I'd be interested to see >> it. > > > I used to muck with $: as you showed, then I discovered the wonderful > world of Rake. Most of the tasks will just do the right thing. For > example, here's the equivalent of my test example above: Here's another approach that I have been very happy with. First, some one-time-only setup: $ mkdir ~/prj # base dir for your projects $ mkdir ~/prj/lib # this will contain some symlinks $ export RUBYLIB=~/prj/lib Now, each time you start a new project, foo, you probably do something like this, to give it the standard project structure for using install.rb: $ cd ~/prj $ mkdir foo $ mkdir foo/lib $ mkdir foo/lib/foo $ touch foo/lib/foo.rb $ touch foo/lib/foo/bar.rb Here's the additional work so you can require this project's files. $ cd ~/prj/lib $ ln -s ../foo/lib/foo . $ ln -s ../foo/lib/foo.rb . The advantages of this setup are: 1. You can require the files using just: require 'foo' # loads ~/prj/foo/lib/foo.rb require 'foo/bar' # loads ~/prj/foo/lib/foo/bar (and this is the same way users who install your lib on their systems using the standard install.rb will do it). 2. No extra command line options. 3. Independent of other tools. 4. Only one modification of RUBYLIB. 5. All your projects see the latest versions of each other without having to install anything locally or remember command line arguments.