All,
Does anybody have any suggestions for packaging their code into a directory
structure during development? Or just code organisation tips generally?
(Note: by “during development” I mean that I have no intention to release the
package, nor to “install” it before running it.)
My basic problem is this: it makes sense to me to have the following:
program/src/file.rb
program/test/tc_file.rb
where tc_file.rb begins<<EOF
require "file"
EOF
Then, when I run the test case, Ruby can’t find “file.rb”.
What do others do?
Cheers,
Gavin
···
–
Gavin Sinclair Software Engineer
Sydney, Australia Soyabean Software Pty Ltd
Gavin Sinclair wrote:
Then, when I run the test case, Ruby can’t find “file.rb”.
I don’t have any general tips around directory structure, etc. but for
this particular program one solution is to use the ‘-I’ option to
specify addition directories for the search path, e.g.
~ cd program/test
~ ruby -I…/src tc_file.rb
To avoid having to type this all the time you could add it to the
RUBYOPT environment variable, e.g.
~ export RUBYOPT=‘-I…/src’
Hope this helps,
Lyle
Gavin Sinclair wrote:
All,
Does anybody have any suggestions for packaging their code into a directory
structure during development? Or just code organisation tips generally?
(Note: by “during development” I mean that I have no intention to release the
package, nor to “install” it before running it.)
I’ve grappled with that one too, but was too shy to ask it here 
I want my working copy of ruby code to show up first on the search path,
but I want the same code to run on any other ruby box the same as on the
development system. Also, I want to be able to use the generic
setup.rb/install.rb, which expect ruby files to be in a lib subdir.
Here’s what I do:
RUBYLIB=~/ruby/prj/lib:~/ruby/prj:~/ruby
(Actually, only the first term is essential.)
Dir structure:
~/ruby/prj/
lib/
project1 → …/project1/lib/
project2 → …/project2/lib/
project1/
lib/
foo.rb
project2/
lib/
bar.rb
Then all my requires look like:
require ‘project2/bar’
and these work ok in both dev and installed situations.
You just have to remember to create a symlink for each new project.
All,
Does anybody have any suggestions for packaging their code […]
Thanks for all the replies. For now, I’m going to use Austin’s tip and modify
$: in the test code before require’ing. Since test code is not real code
anyway, hacks are acceptable.
But Joel’s message has been copied into my “Ruby Gems” folder, and I hope to
implement his links scheme one day. It’s very clever.
Cheers,
Gavin
···
From: “Gavin Sinclair” gsinclair@soyabean.com.au
There is a way to do this from the program, to wit ‘$:’.
$: << '../src'
require file.rb
There is no English equivalent of $: recorded in Pickaxe.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.10.28 at 13.56.28
···
On Tue, 29 Oct 2002 03:10:06 +0900, Lyle Johnson wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Gavin Sinclair wrote:
Then, when I run the test case, Ruby can’t find “file.rb”.
I don’t have any general tips around directory structure, etc. but
for this particular program one solution is to use the ‘-I’ option
to specify addition directories for the search path, e.g.