ScriptEngineManager and Ruby 1.9 on a script-by-script basis

Hi all.

I found this documented in the Wiki:

System.setProperty("org.jruby.embed.compat.version", "JRuby1.9");
JRubyScriptEngineManager manager = new JRubyScriptEngineManager();
JRubyEngine engine = (JRubyEngine) manager.getEngineByName("jruby");

This is handy, but I was wondering if it’s possible to set this on a
script by script basis.

If it’s possible then we can use the #! line to decide which one to
run. It will also make unit tests more sensible if they don’t have to
set a global system property.

TX

On Sun, Apr 3, 2011 at 9:08 PM, Trejkaz [email protected] wrote:

Hi all.

I found this documented in the Wiki:

System.setProperty(“org.jruby.embed.compat.version”, “JRuby1.9”);
JRubyScriptEngineManager manager = new JRubyScriptEngineManager();
JRubyEngine engine = (JRubyEngine) manager.getEngineByName(“jruby”);

This is handy, but I was wondering if it’s possible to set this on a
script by script basis.

Before, it was possible but not now. Because, JRuby works with not
just the script users write. For example, JRuby needs one of two sets
of Ruby code for a built-in library. If you see JRuby’s lib/ruby
directory, you’ll find 1.8 and 1.9 directories and hundreds of(?) Ruby
code in those directories. When JRuby instantiates Ruby runtime, one
set of them is loaded on the runtime. When those days that version
change was possible, JRuby worked using 1.8 library and 1.9 grammar or
vise versa, or 1.8 and 1.9 libraries were mixed on the same runtime.
That might have ended up in unexpected results. This is why version
must be specified before Ruby runtime is instantiated and never be
changed after the instantiation.

-Yoko

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs