本文整理汇总了Java中org.jruby.internal.runtime.GlobalVariables类的典型用法代码示例。如果您正苦于以下问题:Java GlobalVariables类的具体用法?Java GlobalVariables怎么用?Java GlobalVariables使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GlobalVariables类属于org.jruby.internal.runtime包,在下文中一共展示了GlobalVariables类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.jruby.internal.runtime.GlobalVariables; //导入依赖的package包/类
public Object execute(Script script, JRubyCompiledScript compiledScript, Map<String, Object> parameters) throws ScriptExecutionException {
GlobalVariables globablVariables = compiledScript.runtime.getGlobalVariables();
if (parameters != null) {
compiledScript.runtime.setGlobalVariables(new ParametersGlobalVariables(compiledScript.runtime, parameters));
}
try {
return rubyToJava(compiledScript.runtime.eval(compiledScript.node));
} finally {
compiledScript.runtime.setGlobalVariables(globablVariables);
}
}
示例2: testLibary
import org.jruby.internal.runtime.GlobalVariables; //导入依赖的package包/类
@Test
public void testLibary()
{
assertTrue("Runtime nicht gesetzt!", Ruby.isGlobalRuntimeReady());
Ruby runtime = Ruby.getGlobalRuntime();
assertNotNull("Modul 'Cuina' nicht definiert!", runtime.getModule("Cuina"));
GlobalVariables vars = runtime.getGlobalVariables();
assertEquals("Variable $switches nicht definiert!", "Switch", vars.get("$switches").getType().getName());
assertEquals("Variable $variables nicht definiert!", "Variable", vars.get("$variables").getType().getName());
}
示例3: shouldWrapJavaIOExceptions
import org.jruby.internal.runtime.GlobalVariables; //导入依赖的package包/类
@Test public void shouldWrapJavaIOExceptions() throws Exception {
Ruby ruby = Ruby.newInstance();
RackInput rackInput = mock(RackInput.class);
when(rackInput.read(null)).thenThrow(new IOException("fake"));
JRubyRackInput subject = new JRubyRackInput(ruby, rackInput);
GlobalVariables globalVariables = ruby.getGlobalVariables();
globalVariables.set("$rack_input", subject);
IRubyObject result =
ruby.evalScriptlet(
"begin; $rack_input.read; rescue IOError => e; \"rescued #{e.message}\"; end");
assertThat(result.asJavaString()).isEqualTo("rescued fake");
}