Accessing from Java a variable fom the JRuby script top-level environment

(Crossposting note: This question has been posted also to the JRuby
mailing list 16 days before, but hasn’t produced any answer so far).

jruby 1.7.23 (1.9.3p551) 2015-11-24 f496dd5 on Java HotSpot™ 64-Bit
Server VM 1.7.0_79-b15 +jit [Windows 7-amd64]

I run a scriptlet in my scripting container like this:

(RubyObject) ro =

where ‘container’ is of type ScriptingContainer. The “local variable
behaviour” is set to “transient”.

The file example.rb contains:


I can retrieve from the Java side the value ‘zzz’ via the variable ‘ro’,
because it is explicitly returned from runScriptlet.

I can also retrieve the value of the global variable $bar using


Is there a way to retrieve the value of the toplevel variable foo?
container.get(“foo”) returns the null pointer. I also tried to change
the local variable behaviour to “persistent”, but still same result.

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