Forum: JRuby Ruby.evalScriptlet: scope of local variables in JSE / OSGi

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.
Gerald P. (Guest)
on 2008-12-29 12:06
Is the scope of a local variable supposed to span multiple calls to
Ruby.evalScriptlet? Are there any differences between running it in
plain Java and running it within an OSGi bundle? Given the following
code fragment:

    Ruby runtime = JavaEmbedUtils.initialize(Collections.EMPTY_LIST);
    try {
      runtime.evalScriptlet("a = 15; ");
      runtime.evalScriptlet("puts \"result: #{a}\"");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

I'm getting the expected

result: 15

when running as a "normal" java application. When I try the same code in
an OSGi bundle, I'm getting

osgi> <script>:1: undefined local variable or method `a' for main:Object
(NameError)
  ...internal jruby stack elided...
  from (unknown).(unknown)(:1)

Is that to be expected?

Any help/hints welcome.

best regards

  Jerry
This topic is locked and can not be replied to.