当前位置: 首页>>代码示例>>Java>>正文


Java JavaEmbedUtils.javaToRuby方法代码示例

本文整理汇总了Java中org.jruby.javasupport.JavaEmbedUtils.javaToRuby方法的典型用法代码示例。如果您正苦于以下问题:Java JavaEmbedUtils.javaToRuby方法的具体用法?Java JavaEmbedUtils.javaToRuby怎么用?Java JavaEmbedUtils.javaToRuby使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jruby.javasupport.JavaEmbedUtils的用法示例。


在下文中一共展示了JavaEmbedUtils.javaToRuby方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resultsCapturesJavaError

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Test(enabled = false) public void resultsCapturesJavaError() throws Exception {
    RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
            new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
            Constants.FRAMEWORK_SWING);
    script.setDriverURL("");
    Ruby interpreter = script.getInterpreter();
    assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
    RubyClass collectorClass = interpreter.getClass("Collector");
    IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
    IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
    IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
    try {
        collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
    } catch (Throwable t) {

    }
    assertEquals(1, result.failureCount());
    Failure[] failures = result.failures();
    assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
            failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
    assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:RubyScriptTest.java

示例2: convert

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@JRubyMethod(required = 1, optional = 2)
public IRubyObject convert(ThreadContext context, IRubyObject[] args) {
    AbstractNode node = NodeConverter.createASTNode(args[0]);

    Object ret = null;
    if (args.length == 1) {
        ret = delegate.convert(
                node,
                null,
                Collections.emptyMap());
    } else if (args.length == 2) {
        ret = delegate.convert(
                node,
                (String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
                Collections.emptyMap());//RubyString.objAsString(context, args[1]).asJavaString());
    } else if (args.length == 3) {
        ret = delegate.convert(
                node,
                (String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
                (Map) JavaEmbedUtils.rubyToJava(getRuntime(), args[2], Map.class));
    }
    return JavaEmbedUtils.javaToRuby(getRuntime(), ret);
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:24,代码来源:ConverterProxy.java

示例3: toRubyObject

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private static IRubyObject toRubyObject(Ruby rubyRuntime, Object value) {

        if (value instanceof List) {
            return toRubyArray(rubyRuntime, (List<Object>) value);
        } else {

            if (isNotARubySymbol(value)) {
                String stringValue = ((String) value);

                if (stringValue.startsWith(":")) {
                    return RubyUtils.toSymbol(rubyRuntime, stringValue.substring(1));
                }
            }

            IRubyObject iRubyObject = JavaEmbedUtils.javaToRuby(rubyRuntime, value);
            return iRubyObject;
        }
    }
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:19,代码来源:RubyHashUtil.java

示例4: defineVariable

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void defineVariable(String variable, Object value) {
    try {
        GlobalVariable v = new GlobalVariable(interpreter, "$" + variable, JavaEmbedUtils.javaToRuby(interpreter, value));
        interpreter.defineVariable(v, Scope.GLOBAL);
    } catch (Throwable t) {
        throw new ScriptException("Failed to define variable " + variable + " value = " + value + ":" + t.getMessage(), t);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:9,代码来源:RubyScript.java

示例5: convertToRuby

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private IRubyObject[] convertToRuby(Object[] javaArgs) {
	if (javaArgs == null || javaArgs.length == 0) {
		return new IRubyObject[0];
	}
	IRubyObject[] rubyArgs = new IRubyObject[javaArgs.length];
	for (int i = 0; i < javaArgs.length; ++i) {
		rubyArgs[i] = JavaEmbedUtils.javaToRuby(this.ruby, javaArgs[i]);
	}
	return rubyArgs;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:JRubyScriptUtils.java

示例6: invokeMethod

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Override
public Object invokeMethod(Object target, String name, Object... args) {
    try {
        IRubyObject rubyObject = JavaEmbedUtils.javaToRuby(container.getProvider().getRuntime(), target);
        return container.callMethod(rubyObject, name, args);
    } catch (Throwable e) {
        throw SpongeUtils.wrapException(target + "." + name, e);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:10,代码来源:JRubyKnowledgeBaseInterpreter.java

示例7: doCompile

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public JRubyCompiledScript doCompile(Script script) throws ScriptCompilationException {
    Ruby runtime = JavaEmbedUtils.initialize(new ArrayList());
    IRubyObject rubyScript = JavaEmbedUtils.javaToRuby(runtime, script.getScriptAsString());
    try {
        Node node = runtime.parse(rubyScript.asSymbol(), "<unknown>", null, 0);
        return new JRubyCompiledScript(runtime, node);
    } catch (Exception e) {
        throw new ScriptExecutionException("Failed to execute script [" + script.getName() + "]", e);
    }
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:11,代码来源:JRubyLocalScriptExecutor.java

示例8: get

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public IRubyObject get(String name) {
    String modifiedName = name.substring(1);

    Object obj = parameters.get(modifiedName);
    if (obj instanceof IAccessor) {
        return ((IAccessor) obj).getValue();
    } else {
        return JavaEmbedUtils.javaToRuby(runtime, obj);
    }
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:11,代码来源:JRubyLocalScriptExecutor.java

示例9: TableImpl

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public TableImpl(Table delegate, Ruby rubyRuntime) {
    super(delegate, rubyRuntime);
    this.delegate = delegate;

    IRubyObject rubyTable = JavaEmbedUtils.javaToRuby(rubyRuntime, delegate);
    rows = new RowsImpl(
        RubyUtils.rubyToJava(rubyRuntime, rubyTable.getInstanceVariables().getInstanceVariable("@rows"), Rows.class),
        rubyRuntime);
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:10,代码来源:TableImpl.java

示例10: toRubyObject

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public IRubyObject toRubyObject(Object object) {
    return JavaEmbedUtils.javaToRuby(ruby.getProvider().getRuntime(), object);
}
 
开发者ID:necr0potenc3,项目名称:uosl,代码行数:4,代码来源:ScriptManager.java

示例11: toRubyObject

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private IRubyObject toRubyObject(Object javaObject)
{
	return JavaEmbedUtils.javaToRuby(runtime, javaObject);
}
 
开发者ID:TheWhiteShadow3,项目名称:cuina,代码行数:5,代码来源:ScriptExecuter.java


注:本文中的org.jruby.javasupport.JavaEmbedUtils.javaToRuby方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。