Skip to content

Example #4 of ScriptingContainer documentation doesn't work #3043

Closed
@abonas

Description

@abonas

source:
http://jruby.org/apidocs/org/jruby/embed/ScriptingContainer.html

This example:

Example 4:
         ScriptingContainer container = new ScriptingContainer();
         script =
          "def message\n" +
              "\"message: #\"\n" +
          "end\n" +
          "message";
         container.put("@message", "What's up?");
         EvalUnit unit = container.parse(script);
         IRubyObject ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));
         container.put("@message", "Fabulous!");
         ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));
         container.put("@message", "That's the way you are.");
         ret = unit.run();
         System.out.println(JavaEmbedUtils.rubyToJava(ret));

first of all, the script variable needs a type (String)
But even after adding it, the script outputs the following:

message: #
message: #
message: #

same result also when initializing the scripting container with LocalVariableBehavior.PERSISTENT
tested with jruby 1.7.18

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions