Created
December 3, 2010 21:28
-
-
Save cowboyd/727585 to your computer and use it in GitHub Desktop.
try to get a top-level constant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.