本文整理匯總了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");
}