Joining scripts?

Q

Qubert

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
 
W

Wesley J Landaker

--Boundary-02=_3dL1/LUk0BNszHI
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Description: signed data
Content-Disposition: inline

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.

Seems like you just want "load":

load '/usr/local/bin/secondscript.rb'

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

=2D-=20
Wesley J. Landaker - (e-mail address removed)
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2


--Boundary-02=_3dL1/LUk0BNszHI
Content-Type: application/pgp-signature
Content-Description: signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/1Ld38KmKTEzW49IRAlFuAJ92tZKj207u6HClq/J4BxYhoaZS8gCcCTKE
XlGxeQEFcITl3D5Nk2blBig=
=Ghdq
-----END PGP SIGNATURE-----

--Boundary-02=_3dL1/LUk0BNszHI--
 
G

gabriele renzi

il 8 Dec 2003 09:31:41 -0800, (e-mail address removed) (Qubert) ha
scritto::

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
 
G

Gavin Sinclair

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top