Running two versions of Ruby - Lessons Learned

A

Alex DeCaria

After experimenting with Ruby 1.9 I've found I really like it and wanted
to make it my main version of Ruby. My problem was that I have two
programs that I use frequently that only work with Ruby 1.8. I want my
programs to run just by clicking the icons on my Windows desktop.
However, when setting the default application for an icon, Windows
forces you to choose between running all the .rb programs using either
1.9 or 1.8 (you can't set some to default to 1.9 and others to default
with 1.8 as far as I can tell).

I was trying to figure out how to get around this, and hit upon the
following:

- I set Ruby 1.9 as the default program for all my .rb icons on my
desktop.

- For thos few programs that need to run under Ruby 1.8 I wrote a simple
ruby script that calls the Kernel.system method:

system( "C:\Ruby\bin\rubyw.exe my_Ruby1.8_program.rb" )

I run this script in Ruby 1.9, but the system method executes the target
program using Ruby 1.8. I have the icon for this script on my desktop,
rather than the icon for the actual 1.8 program. Thus, it is
transparent to me whether, when I click on an icon, it runs in Ruby 1.8
or in Ruby 1.9.

It seems to work fine. However, if others have a more elegant or better
solution, or can see potential problems with this solution, I would be
interested in hearing about it.

Thanks.

--Alex
 
D

Dane Jensen

- For thos few programs that need to run under Ruby 1.8 I wrote a
simple
ruby script that calls the Kernel.system method:

system( "C:\Ruby\bin\rubyw.exe my_Ruby1.8_program.rb" )

You should use exec instead. system runs the script as a sub process
with your wrapper just sitting in memory waiting for it to exit. exec
replaces your wrapper with the called script.

-Dane
 
S

Siep Korteling

Alex said:
After experimenting with Ruby 1.9 I've found I really like it and wanted
to make it my main version of Ruby. My problem was that I have two
programs that I use frequently that only work with Ruby 1.8. I want my
programs to run just by clicking the icons on my Windows desktop.
However, when setting the default application for an icon, Windows
forces you to choose between running all the .rb programs using either
1.9 or 1.8 (you can't set some to default to 1.9 and others to default
with 1.8 as far as I can tell).(...)

If you have (or create) on your desktop a shortcut to your .rb file, you
can edit the properties of this shortcut. On the tab "shortcut" the
entry "target" will contain the path to your .rb file. Modify this to:
"path\to\ruby1.8\bin\ruby.exe path\to\rb".

hth,

Siep
 
A

Alex DeCaria

Dane said:
You should use exec instead. system runs the script as a sub process
with your wrapper just sitting in memory waiting for it to exit. exec
replaces your wrapper with the called script.

-Dane

Thanks. I was wondering what the difference between system and exec
was. That helps.

--Alex
 
A

Alex DeCaria

If you have (or create) on your desktop a shortcut to your .rb file, you
can edit the properties of this shortcut. On the tab "shortcut" the
entry "target" will contain the path to your .rb file. Modify this to:
"path\to\ruby1.8\bin\ruby.exe path\to\rb".

hth,

Siep

I thought there must be a way to do it without writing a separate
script. Thanks. --Alex
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top