Replace all hard-coded instance of the the URLs with a variable or a constant. Store that different URLs in a hash in a file. Something like this:
URLS = {
}
Then, in whatever you're using to run the script, add an option to specify the environment when running. one way to do it would be to use ARGV. Then run the script for the environment, let's say you want "dev":
myscript.rb dev
In the script, assuming that you have access to the URLS constant defined above, then you could then get the URL associated with the environment you specified at the command line by doing something like this:
TARGET_URL = URLS[ARGV[0].to_sym]
And then use TARGET_URL wherever you need to call goto in place of the hard-coded URL.
There are better ways of doing this but it sounds like you're just looking for ideas to start organizing, HTH.
John