name of current ruby iterpreter

  • Thread starter Joel VanderWerf
  • Start date
J

Joel VanderWerf

How can I find the name of the current ruby interpreter? It's not $0,
since that's the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.
 
R

Ryan Pavlik

How can I find the name of the current ruby interpreter? It's not $0,
since that's the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.

require 'rbconfig'

ruby = Config::CONFIG.fetch('bindir') + "/" +
Config::CONFIG.fetch('RUBY_INSTALL_NAME')
ruby = Config.expand(ruby)

exec ruby, "-e", 'puts VERSION'


AFAIK, "/" works in win32. HTH,
 
J

Joel VanderWerf

Ryan said:
require 'rbconfig'

ruby = Config::CONFIG.fetch('bindir') + "/" +
Config::CONFIG.fetch('RUBY_INSTALL_NAME')
ruby = Config.expand(ruby)

exec ruby, "-e", 'puts VERSION'

Almost there. It won't work if you've got 1.8.0 and 1.8.1 both installed
(if you installed 1.8.1 later, requiring 'rbconfig' generates an error).
And it doesn't detect that you started ruby with an alias ('alias
rv=ruby -v)', but it's good enough for my purposes. What I was looking
for was a way to see the original command line. On linux I could use the
proc file system, but that's just linux...

Thanks!
AFAIK, "/" works in win32. HTH,

It does, though I tend to use File.join for clarity.
 
R

Ryan Pavlik

Ryan Pavlik wrote:

Almost there. It won't work if you've got 1.8.0 and 1.8.1 both
installed (if you installed 1.8.1 later, requiring 'rbconfig'
generates an error).

Maybe installing one over the other... that's not a good thing. I
suggest using Encap. ;-) But it works fine with 1.8.1 here.
And it doesn't detect that you started ruby with an alias ('alias
rv=ruby -v)', but it's good enough for my purposes.

That, of course, is impossible.
What I was looking for was a way to see the original command
line. On linux I could use the proc file system, but that's just
linux...

Oh, well, you should have said that right off. That's not generally
possible. Certainly, there's no (portable) way to get the invocation
from the shell or otherwise. Even if you could, aliases are expanded
before the shell executes the command, so you couldn't get that,
either.

<snip>
 
J

Joel VanderWerf

Ryan said:
Maybe installing one over the other... that's not a good thing. I
suggest using Encap. ;-) But it works fine with 1.8.1 here.

Good idea...I've been meaning to lear encap or stow. But your suggestion
works with 1.8.1 here, also (I guess since that's the last installed
version), so I'm happy.
 

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
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top