Getting Ruby Path at runtime?

R

Ronald Fischer

Is it possible to find out under Windows, which Ruby has been used to
run a program?
Example: A program is invoked by

C:\inst\ruby186\bin\ruby.exe appl.rb

Is it then possible to find out inside appl.rb the whole path

C:\inst\ruby186\bin\ruby.exe

? If not, is it at least possible to find out

- the Ruby version (1.8.6) and
- whether it is executed by Ruby or JRuby?


Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
 
F

F. Senault

Le 27 juillet à 11:41, Ronald Fischer a écrit :
- the Ruby version (1.8.6) and

You have the RUBY_VERSION constants and a few others :=> 0

And the same, without RUBY_.
- whether it is executed by Ruby or JRuby?

You probably have other constants telling you that. I'd suggest you
inspect the contents of Object.constants to find them.

Fred
 
J

James Edward Gray II

Is it possible to find out under Windows, which Ruby has been used to
run a program?
Example: A program is invoked by

C:\inst\ruby186\bin\ruby.exe appl.rb

Is it then possible to find out inside appl.rb the whole path

C:\inst\ruby186\bin\ruby.exe

?

Sure:

Firefly:~/Desktop$ /usr/local/bin/ruby find_ruby.rb
/usr/local/bin/ruby
Firefly:~/Desktop$ /usr/bin/ruby find_ruby.rb
/usr/bin/ruby
Firefly:~/Desktop$ cat find_ruby.rb
#!/usr/bin/env ruby -wKU

require "rbconfig"

puts File.join(Config::CONFIG["bindir"], Config::CONFIG
["ruby_install_name"])

__END__

Hope that helps.

James Edward Gray II
 
R

Ronald Fischer

Is it possible to find out under Windows, which Ruby has=20
been used to
require "rbconfig"
=20
puts File.join(Config::CONFIG["bindir"], Config::CONFIG=20
["ruby_install_name"])

Great!!!

May I ask where I can find a documentation about rbconfig?
Maybe there is other useful stuff in it.=20

I checked http://stdlib-doc.rubyforge.org/rdoc/index.html,
but rbconfig was not mentioned.

Or does the fact that rbconfig is not mentioned in the=20
standard library page, mean, that these configuration
variables (bindir, ruby_install_name) are not part of
the official Ruby API? I would like to keep my programs
upward compatible (to future Ruby versions), plus compatible
to JRuby, as much as possible.

Ronald
 
R

Ronald Fischer

[...] is it at least possible to find out
=20
=20
You can do a check for the JRUBY_VERSION constant. If it=20
exists then you are
using jruby.

Thanks a lot.

Ronald
 

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,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top