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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-01-05 11:27
(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(TM) 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 =
(RubyObject)container.runScriptlet(org.jruby.embed.PathType.RELATIVE,"example.rb");

where 'container' is of type ScriptingContainer. The "local variable
behaviour" is set to "transient".

The file example.rb contains:

foo='xxx'
$bar='yyy'
'zzz'

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

container.get("$bar")

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 topic is locked and can not be replied to.