On Jul 25, 2008, at 11:55 AM, Bill Kelly wrote:
> From: "Eric Hodel" <drbrain / segment7.net>
>> On Jul 25, 2008, at 01:21 AM, Bill Kelly wrote:
>>>
>>> From: http://ruby-design.pbwiki.com/f/ruby-core-20080430.txt
>> Evan is mistaken.  You can calculate the current ruby like this:
>> ruby = File.join RbConfig::CONFIG['bindir'],   
>> RbConfig::CONFIG['ruby_install_name']
>> ruby << RbConfig::CONFIG['EXEEXT']
>
> [2008/04/30 20:34:22] <evan> thats the installed location
> [2008/04/30 20:34:25] <evan> not the current running one
> [2008/04/30 20:34:37] <evan> an great example of that is doing ../../ 
> blah/bin/ruby
>
>
> (Note, I don't have any vested interest in this, I am merely quoting  
> from the IRC logs... For example, I don't know why it was important  
> to find the current running binary.

RubyGems needs to know the path to ruby so it can `#{ruby} extconf.rb`  
when building extensions.   Ruby may not be installed as `ruby` or you  
may have multiple versions installed either in different paths or with  
different names.  Just picking `ruby` every time may lead to an  
extension getting built with an incompatible ruby.

> But I'm not sure how RUBY_ENGINE was supposed to help in the ../../ 
> blah/bin/ruby situation anyway? :)

rbconfig.rb takes care of relative paths for you:

$ cat rbconfig.rb
[...]
module Config
[...]
   TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/i686- 
darwin9.4.0")
[...]
   CONFIG["prefix"] = (TOPDIR || DESTDIR + "/usr/local")
[...]
   CONFIG["exec_prefix"] = "$(prefix)"
   CONFIG["bindir"] = "$(exec_prefix)/bin"
[...]
   def Config::expand(val, config = CONFIG)
     [code that expands $()]
   end
   CONFIG.each_value do |val|
     Config::expand(val)
   end
[...]

So you always get a full path to your current interpreter's executable.

$ ../../usr/bin/ruby -rubygems -e 'p Gem.ruby'
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby"