From: Hassan Schroeder on
Is there a way to tell from within a program which executable is being
used -- which executable, not the version -- to run it?

Seems like there should be, but I'm striking out...

TIA,
--
Hassan Schroeder ------------------------ hassan.schroeder(a)gmail.com
twitter: @hassan

From: Joseph E. Savard on

The best way is to check your path or your #! Line....


From IRB:

ruby-1.9.2-head > RUBY_VERSION
=> "1.9.2"
ruby-1.9.2-head > RUBY_PLATFORM
=> "i386-darwin9.8.0"
ruby-1.9.2-head > RUBY_RELEASE_DATE
=> "2010-07-14"
ruby-1.9.2-head > RUBY_PATCHLEVEL
=> -1
ruby-1.9.2-head >


HERE's the money shot!


FROM A RUBY PROGRAM: [args.rb]
puts "The name of the progrma laucnhed is #{$0} OR #{$PROGRAM_NAME}"
ARGV.each do|a|

puts "Argument: #{a}"
end

puts "And finally the ruby executable #{ENV['_']}"



<MANISH:jes> [07-27 16:17] 0 529:29 (14.35 Mb) • ~
! irb args.rb a s d
ruby-1.9.2-head >
ruby-1.9.2-head > puts "The name of the progrma laucnhed is #{$0} OR
#{$PROGRAM_NAME}"
The name of the progrma laucnhed is args.rb OR args.rb
=> nil
ruby-1.9.2-head > ARGV.each do|a|
ruby-1.9.2-head >
ruby-1.9.2-head > puts "Argument: #{a}"
ruby-1.9.2-head ?> end
Argument: a
Argument: s
Argument: d
=> ["a", "s", "d"]
ruby-1.9.2-head >
ruby-1.9.2-head > puts "And finally the ruby executable #{ENV['_']}"
And finally the ruby executable
/Users/jes/.rvm/rubies/ruby-1.9.2-head/bin/irb
=> nil
ruby-1.9.2-head >


OR RBCONFIG if you like:
ruby-1.9.2-head > require "rbconfig"
=> false
ruby-1.9.2-head > puts File.join(Config::CONFIG["bindir"],
Config::CONFIG["ruby_install_name"])
/Users/jes/.rvm/rubies/ruby-1.9.2-head/bin/ruby
=> nil
ruby-1.9.2-head >



Make sense?



> From: Hassan Schroeder <hassan.schroeder(a)gmail.com>
> Reply-To: <ruby-talk(a)ruby-lang.org>
> Date: Wed, 28 Jul 2010 05:26:42 +0900
> To: ruby-talk ML <ruby-talk(a)ruby-lang.org>
> Subject: Which Ruby is in use?
>
> Is there a way to tell from within a program which executable is being
> used -- which executable, not the version -- to run it?
>
> Seems like there should be, but I'm striking out...
>
> TIA,
> --
> Hassan Schroeder ------------------------ hassan.schroeder(a)gmail.com
> twitter: @hassan
>


From: Joseph E. Savard on
In 1.9:
RUBY_COPYRIGHT
RUBY_DESCRIPTION String Version number 1.9 & interpreter arch.
RUBY_ENGINE String The name of the Ruby interpreter
RUBY_PATCHLEVEL
RUBY_PLATFORM

Results in irb:
ruby-1.9.2-head > RUBY_COPYRIGHT
=> "ruby - Copyright (C) 1993-2010 Yukihiro Matsumoto"
ruby-1.9.2-head > RUBY_DESCRIPTION
=> "ruby 1.9.2dev (2010-07-14 revision 28640) [i386-darwin9.8.0]"
ruby-1.9.2-head > RUBY_ENGINE
=> "ruby"
ruby-1.9.2-head > RUBY_PATCHLEVEL
=> -1
ruby-1.9.2-head > RUBY_PLATFORM
=> "i386-darwin9.8.0"
ruby-1.9.2-head >

Lots of ways to skin the cat.


> From: Hassan Schroeder <hassan.schroeder(a)gmail.com>
> Reply-To: <ruby-talk(a)ruby-lang.org>
> Date: Wed, 28 Jul 2010 05:26:42 +0900
> To: ruby-talk ML <ruby-talk(a)ruby-lang.org>
> Subject: Which Ruby is in use?
>
> Is there a way to tell from within a program which executable is being
> used -- which executable, not the version -- to run it?
>
> Seems like there should be, but I'm striking out...
>
> TIA,
> --
> Hassan Schroeder ------------------------ hassan.schroeder(a)gmail.com
> twitter: @hassan
>
RUBY_COPYRIGHT
RUBY_DESCRIPTION
RUBY_ENGINE String
RUBY_PATCHLEVEL
RUBY_PLATFORM


From: Hassan Schroeder on
On Tue, Jul 27, 2010 at 2:20 PM, Joseph E. Savard
<joseph.savard(a)sabre-holdings.com> wrote:

As I said, I'm not interested in the version, just the path to the executable.

> puts "And finally the ruby executable #{ENV['_']}"

Doesn't appear to work in JRuby. Do you know if it works in anything
else besides MRI?

--
Hassan Schroeder ------------------------ hassan.schroeder(a)gmail.com
twitter: @hassan

From: Joel VanderWerf on
Hassan Schroeder wrote:
> On Tue, Jul 27, 2010 at 2:20 PM, Joseph E. Savard
> <joseph.savard(a)sabre-holdings.com> wrote:
>
> As I said, I'm not interested in the version, just the path to the executable.
>
>> puts "And finally the ruby executable #{ENV['_']}"
>
> Doesn't appear to work in JRuby. Do you know if it works in anything
> else besides MRI?
>

Maybe this will work?

>> File.join *Config::CONFIG.values_at("bindir", "ruby_install_name")
=> "/usr/local/bin/ruby"