Changing variables mid-script

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Say I had a script which read:

task.start
while $connect do
task.receive
end
task.stop

Could I make the variable $connect false whilst the script it running
from
an outside source, other than reading from a file?

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

iD8DBQFGW/bb2vy7v+d+psQRAhuHAKD1DCmDiNjGeI/YqZIaKRnHwXYR9ACfYII5
mX2TMedJJQvqiWXX1TUpdJQ=
=o3gy
-----END PGP SIGNATURE-----

Fred P. wrote:

Could I make the variable $connect false whilst the script it running from
an outside source, other than reading from a file?

Yes. You could use a signal handler or DRb, for example. For signals,
put this somewhere before your while loop:

trap “USR1” do
$connect = false
end

Then "kill -USR1 " will cause $connect to become
false.

DRb is more complicated, but exposes a much richer interface.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs