本文整理汇总了Java中org.jruby.RubyObject.callMethod方法的典型用法代码示例。如果您正苦于以下问题:Java RubyObject.callMethod方法的具体用法?Java RubyObject.callMethod怎么用?Java RubyObject.callMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.RubyObject
的用法示例。
在下文中一共展示了RubyObject.callMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rubyCompare
import org.jruby.RubyObject; //导入方法依赖的package包/类
int rubyCompare(RubyObject l, RubyObject r) {
ThreadContext context = l.getMetaClass().getRuntime().getCurrentContext();
IRubyObject result;
try {
result = l.callMethod(context, "<=>", r);
} catch (RaiseException e) {
// handle objects "lying" about responding to <=>, ie: an Array containing non-comparable keys
if (context.runtime.getNoMethodError().isInstance(e.getException())) {
return 0;
}
throw e;
}
return result.isNil() ? 0 : RubyNumeric.num2int(result.convertToInteger());
}
示例2: executeScript
import org.jruby.RubyObject; //导入方法依赖的package包/类
private Object executeScript(String name, String main, Object... args)
{
RubyObject scriptInstance = instanceCache.get(name);
if (scriptInstance == null)
{
Logger.log(ScriptExecuter.class, Logger.ERROR,
"Script-Instance for " + name + " do not exists.");
return null;
}
try
{
Logger.log(ScriptExecuter.class, Logger.DEBUG,
"execute script: " + name + "." + main);
// runtime.defineVariable( new GlobalVariable(runtime, "$trigger", toRubyObject(trigger)), Scope.THREAD);
IRubyObject result;
if (args != null && args.length > 0)
result = scriptInstance.callMethod(main, toRubyObject(args));
else
result = scriptInstance.callMethod(main);
return JavaEmbedUtils.rubyToJava(result);
}
catch (RaiseException e)
{
Logger.log(ScriptExecuter.class, Logger.ERROR, e);
return null;
}
}