本文整理汇总了Java中org.jruby.javasupport.JavaEmbedUtils.rubyToJava方法的典型用法代码示例。如果您正苦于以下问题:Java JavaEmbedUtils.rubyToJava方法的具体用法?Java JavaEmbedUtils.rubyToJava怎么用?Java JavaEmbedUtils.rubyToJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.javasupport.JavaEmbedUtils
的用法示例。
在下文中一共展示了JavaEmbedUtils.rubyToJava方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
LOG.debug("Evaluating JRuby expression: {1}", expression);
try {
final RubyInstanceConfig config = new RubyInstanceConfig();
config.setCompatVersion(CompatVersion.RUBY1_9);
final Ruby runtime = JavaEmbedUtils.initialize(new ArrayList<String>(), config);
final StringBuilder localVars = new StringBuilder();
for (final Entry<String, ?> entry : values.entrySet()) {
runtime.getGlobalVariables().set("$" + entry.getKey(), JavaEmbedUtils.javaToRuby(runtime, entry.getValue()));
localVars.append(entry.getKey()) //
.append("=$") //
.append(entry.getKey()) //
.append("\n");
}
final IRubyObject result = runtime.evalScriptlet(localVars + expression);
return JavaEmbedUtils.rubyToJava(runtime, result, Object.class);
} catch (final RuntimeException ex) {
throw new ExpressionEvaluationException("Evaluating JRuby expression failed: " + expression, ex);
}
}
示例2: findAssertionProviderMethods
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void findAssertionProviderMethods() {
IRubyObject ro = interpreter.evalScriptlet("Object.private_instance_methods");
String[] methods = (String[]) JavaEmbedUtils.rubyToJava(interpreter, ro, String[].class);
assertionProviderList = new ArrayList<String>();
for (Object method : methods) {
if (method.toString().startsWith("marathon_assert_")) {
assertionProviderList.add(method.toString());
}
}
}
示例3: convertFromRuby
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
if (result instanceof RubyArray && returnType.isArray()) {
result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
}
return result;
}
示例4: evaluate
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Override
public Object evaluate(DeferredObject[] parameters) throws HiveException {
Object[] args = new Object[argsConverters.length];
for (int i = 0; i < args.length; i++) {
args[i] = argsConverters[i].convert(parameters[i + scriptParamPos + 1].get());
}
Object ret;
if (mode == MODE.EVAL) {
for (int i = 0; i < args.length; i++) {
container.put("@arg" + (i + 1), args[i]);
}
ret = JavaEmbedUtils.rubyToJava((IRubyObject) (evalUnit.run()));
} else {
ret = container.callMethod(receiver, evaluateMethod, args);
}
if (scriptParamPos == 0) {
// should return String
if (ret != null) {
retText.set(ret.toString());
return retText;
} else {
return null;
}
} else {
return ret;
}
}
示例5: toJavaObject
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private static Object toJavaObject(Object rubyObject) {
if (rubyObject instanceof IRubyObject) {
IRubyObject iRubyObject = (IRubyObject) rubyObject;
return JavaEmbedUtils.rubyToJava(iRubyObject);
}
return rubyObject;
}
示例6: executeScript
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的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;
}
}
示例7: readGlobals
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void readGlobals() {
interpreter.evalScriptlet("$marathon = RubyMarathon.new('" + driverURL + "')");
IRubyObject marathon = interpreter.evalScriptlet("$marathon");
interpreter.evalScriptlet("$test = proc { test }");
runtime = (MarathonRuby) JavaEmbedUtils.rubyToJava(interpreter, marathon, MarathonRuby.class);
}