[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting Ruby Path at runtime?

Ronald Fischer

7/27/2007 9:41:00 AM

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
--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

4 Answers

F. Senault

7/27/2007 9:51:00 AM

0

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 :
>> 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
--
Your loved one are waiting, break out of your cage
You have the power, give into your rage
Listen to pride now for once he is right (Ayreon, The Human
Listen to reason, let us be your guide Equation, Day 14 : Pride)

James Gray

7/27/2007 1:08:00 PM

0

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

> 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

Ronald Fischer

7/30/2007 7:19:00 AM

0

> > 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/...,
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

Ronald Fischer

7/30/2007 7:20:00 AM

0

> > [...] 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