Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Created December 3, 2010 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboyd/727585 to your computer and use it in GitHub Desktop.
Save cowboyd/727585 to your computer and use it in GitHub Desktop.
try to get a top-level constant
package foo;
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.internal.LocalContext;
public class Fooby {
public static void main(String[] args) {
ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
ruby.runScriptlet("class Foo;end");
System.out.println("ruby.get(\"Foo\") = " + ruby.get("Foo"));
System.out.println("ruby.runScriptlet(\"JRUBY_VERSION\") = " + ruby.runScriptlet("JRUBY_VERSION"));
}
}
/**output
ruby.get("Foo") = null
ruby.runScriptlet("JRUBY_VERSION") = 1.5.3
*/
@yokolet
Copy link

yokolet commented Dec 8, 2010

Sorry about that. runScriptlet('Foo') is a simple and steady way and works surely on both 1.5.x and 1.6.x. It is definitely a right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment