Portable method of launching another Ruby interpreter

I’m working on a project that requires a “clean”, newly launched Ruby
interpreter to perform a little magic.

I’m looking for a portable way to determine the path to the Ruby
interpreter
being used by the current environment. At the very least I’d like for
this
to work across Ruby 1.8.7, Ruby 1.9.2, JRuby, and Rubinius.

I’ve seen people suggest using Config::CONFIG for this, however from
what I
can tell this doesn’t work on JRuby.

Are there any portable solutions to this problem?

On 09/08/2010 10:56 AM, Tony A. wrote:

Are there any portable solutions to this problem?

Doesn’t it work on jruby?

$ jruby -v -rrbconfig -e ‘p
File.join(*Config::CONFIG.values_at(“bindir”, “ruby_install_name”))’
jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) (Java
HotSpot™ 64-Bit Server VM 1.6.0_20) [amd64-java]
“/usr/local/jruby/bin/jruby”

I’ve seen people suggest using Config::CONFIG for this, however from
what I
can tell this doesn’t work on JRuby.

Are there any portable solutions to this problem?

It should work on jruby, unless jruby was run as a jar file (like java
-cp jruby-1.4.9.jar) in which case it won’t.

Gem.ruby
is same as os gem’s OS.ruby_bin

I would be happy to implement a patch to the os gem to make it work with
jruby from a jar, but it doesn’t yet.
-r

Whoops, my bad…

All that said, I think I found a better solution… write a wrapper
script
to accomplish what I want and ship it in the gem’s bin. Then RubyGems
handles selecting the appropriate Ruby interpreter.

On Wed, Sep 8, 2010 at 12:58 PM, Joel VanderWerf

On Wed, Sep 8, 2010 at 9:07 PM, Ryan D. [email protected]
wrote:

I always use Gem.ruby

I’m not sure if the jruby team has patched that to work for jars or not (or if it even needs patching for that matter–I don’t use jruby, sorry).

I believe we did modify it at some point:

~/projects/jruby âž” java -jar lib/jruby-complete.jar -rubygems -e “p
Gem.ruby”
“java -jar /Users/headius/projects/jruby/lib/jruby-complete.jar”

On Sep 8, 2010, at 10:56 , Tony A. wrote:

Are there any portable solutions to this problem?
I always use Gem.ruby

I’m not sure if the jruby team has patched that to work for jars or not
(or if it even needs patching for that matter–I don’t use jruby,
sorry).