Joining scripts?

I have been working on a couple of Ruby wrappers for some fortran
programs. They are running a bit long (300+ lines), however Ruby has
been excellent in handling them.

My concerns are they are a bit too long to join together in one program,
but they will often run together. I want the second script to be run
independently, but if the first one is run, I want the second to be
called from within the first.

Is the best way to accomplish this to write a line in the first script:
/usr/local/bin/secondscript.rb

This doesn’t seem to be the Ruby way since it relies on the shell, plus
I would like to send some global variables across if continued from the
first script.

Any advice would be appreciated.
Chris

Seems like you just want “load”:

load ‘/usr/local/bin/secondscript.rb’

It works like require, but will always evaluate the file, instead of
doing so conditionally.

···

On Monday 08 December 2003 10:32 am, Qubert wrote:

I have been working on a couple of Ruby wrappers for some fortran
programs. They are running a bit long (300+ lines), however Ruby has
been excellent in handling them.

My concerns are they are a bit too long to join together in one
program, but they will often run together. I want the second script
to be run independently, but if the first one is run, I want the
second to be called from within the first.

Is the best way to accomplish this to write a line in the first
script: /usr/local/bin/secondscript.rb

This doesn’t seem to be the Ruby way since it relies on the shell,
plus I would like to send some global variables across if continued
from the first script.


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2

Is the best way to accomplish this to write a line in the first script:
/usr/local/bin/secondscript.rb

This doesn’t seem to be the Ruby way since it relies on the shell, plus
I would like to send some global variables across if continued from the
first script.

I’ll wrap up the main functions in a method.
then adding something like this

script 1

if FILE=$0
function_one()
load ‘script2’
function_two()
end

#script 2
if FILE=$0
function_two()
end

and so on… maybe someone has a better way

···

il 8 Dec 2003 09:31:41 -0800, qubert@austin.rr.com (Qubert) ha scritto::

Any advice would be appreciated.
Chris

[gabriele renzi ha scritto:]

I’ll wrap up the main functions in a method.
then adding something like this

script 1

if FILE=$0
function_one()
load ‘script2’
function_two()
end

#script 2
if FILE=$0
function_two()
end

and so on… maybe someone has a better way

File 1

class A
def x; end
def y; end
def z; end
def A.run(args); end
end

if FILE == $0
A.run(ARGV)
end

File 2

require ‘File 1’

class B
def x; end
def y; end
def z; end
def B.run(args); end
end

if FILE == $0
B.run(ARGV)
end

Although my simple scripts generally begin life as a bunch of top-level
methods and so on, they usually evolve to an “application” class. It’s
just easier to arrange things that way I find.

Gavin