Forum: Ruby Which ruby is running me?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2009-04-20 01:46
(Received via mailing list)
So I have despaired of getting mutexes, threads and forks to coexist
peacably in Ruby. (As soon as the child process touches a mutex that
existed in the parent.... Bad Things can happen.)

So Plan B is to
  - spin a thread
  - to mind a fork
  - that just execs
a new instance of Ruby.

Now I tend to have several versions of Ruby lying around on my Box.

What is the One True Way of finding the path to _the_ instance of ruby
that is currently executing this script?

GNU "Make" is pretty good about this, it has a $(MAKE) variable that
gives the exact path of make that is running.




John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-04-20 01:51
(Received via mailing list)
On Apr 19, 2009, at 6:45 PM, John Carter wrote:

> What is the One True Way of finding the path to _the_ instance of ruby
> that is currently executing this script?

I'm pretty sure this always works:

$ ruby -r rbconfig -e 'p File.join(Config::CONFIG.values_at(*%w[bindir
ruby_install_name])) + Config::CONFIG["EXEEXT"]'
"/usr/local/bin/ruby"

James Edward Gray II
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2009-04-20 03:46
(Received via mailing list)
On Mon, 20 Apr 2009, James Gray wrote:

> On Apr 19, 2009, at 6:45 PM, John Carter wrote:
>
>> What is the One True Way of finding the path to _the_ instance of ruby
>> that is currently executing this script?
>
> I'm pretty sure this always works:
>
> $ ruby -r rbconfig -e 'p File.join(Config::CONFIG.values_at(*%w[bindir
> ruby_install_name])) + Config::CONFIG["EXEEXT"]'
> "/usr/local/bin/ruby"

Thanks! Ooo.. a tad ugly though... Ah, well, at least I wasn't missing
the obvious for a change. :-)

John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-04-21 00:13
(Received via mailing list)
On Apr 19, 2009, at 6:44 PM, John Carter <john.carter@tait.co.nz> wrote:

>> $ ruby -r rbconfig -e 'p File.join(Config::CONFIG.values_at(*
>> %w[bindir ruby_install_name])) + Config::CONFIG["EXEEXT"]'
>> "/usr/local/bin/ruby"
>
> Thanks! Ooo.. a tad ugly though... Ah, well, at least I wasn't missing
> the obvious for a change. :-)

require 'rubygems'
Gem.ruby

$ ruby -rubygems -e 'p Gem.ruby'
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby"
$ ruby18 -rubygems -e 'p Gem.ruby'
"/usr/local/bin/ruby18"
$ ruby19 -e 'p Gem.ruby' # require 'rubygems' is automatic on 1.9
"/usr/local/bin/ruby19"
This topic is locked and can not be replied to.