Getting Ruby Path at runtime?

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

Le 27 juillet à 11:41, Ronald F. a écrit :

  • the Ruby version (1.8.6) and

You have the RUBY_VERSION constants and a few others :

RUBY_VERSION
=> “1.8.6”

RUBY_PLATFORM
=> “i386-freebsd6”

RUBY_RELEASE_DATE
=> “2007-03-13”

RUBY_PATCHLEVEL
=> 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

On Jul 27, 2007, at 4:41 AM, Ronald F. wrote:

?
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 G. II

On 7/27/07, Ronald F. [email protected] wrote:

? 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?

You can do a check for the JRUBY_VERSION constant. If it exists then you
are
using jruby.

Is it possible to find out under Windows, which Ruby has
been used to
run a program?

require “rbconfig”

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

Great!!!

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

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
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

[…] is it at least possible to find out

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

You can do a check for the JRUBY_VERSION constant. If it
exists then you are
using jruby.

Thanks a lot.

Ronald