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


Java IRubyObject.callMethod方法代码示例

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


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

示例1: resultsCapturesJavaError

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的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: getValueFromView

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public Object getValueFromView(Object view, String[] path) {
    if(view instanceof IRubyObject) {
        IRubyObject o = (IRubyObject)view;
        for(String key : path) {
            if(o == null || o.isNil()) { return null; }
            o = o.callMethod(o.getRuntime().getCurrentContext(), "[]",
                    RubyString.newUnicodeString(o.getRuntime(), key));
        }
        if(o instanceof ConcreteJavaProxy) {
            return ((ConcreteJavaProxy)o).getObject();
        }
        return ((o == null) || o.isNil()) ? null : o;
    } else if(path.length == 0) {
        return view;    // to allow . value to work
    }
    return null;
}
 
开发者ID:haplo-org,项目名称:haplo-safe-view-templates,代码行数:18,代码来源:JRubyJSONDriver.java

示例3: eq

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
@JRubyMethod(name = "==")
public IRubyObject eq(ThreadContext context, IRubyObject other) {
    Ruby runtime = context.runtime;
    if (!(other instanceof RubyMessage))
        return runtime.getFalse();
    RubyMessage message = (RubyMessage) other;
    if (descriptor != message.descriptor) {
        return runtime.getFalse();
    }

    for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) {
        IRubyObject thisVal = getField(context, fdef);
        IRubyObject thatVal = message.getField(context, fdef);
        IRubyObject ret = thisVal.callMethod(context, "==", thatVal);
        if (!ret.isTrue()) {
            return runtime.getFalse();
        }
    }
    return runtime.getTrue();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:21,代码来源:RubyMessage.java

示例4: valueToStringRepresentation

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public String valueToStringRepresentation(Object value) {
    if(value instanceof RubyArray || value instanceof RubyHash) {
        return null;
    }
    if(value instanceof IRubyObject) {
        IRubyObject o = (IRubyObject)value;;
        if(o.isNil()) { return null; }
        IRubyObject str = o.callMethod(o.getRuntime().getCurrentContext(), "to_s");
        if(!(str instanceof RubyString)) { return null; }
        return ((RubyString)str).decodeString();
    }
    return (value == null) ? null : value.toString();
}
 
开发者ID:haplo-org,项目名称:haplo-safe-view-templates,代码行数:14,代码来源:JRubyJSONDriver.java

示例5: toCHM

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
private ConcurrentHashMap<IRubyObject, IRubyObject> toCHM(ThreadContext context, IRubyObject options) {
    Ruby runtime = context.getRuntime();
    if (!options.isNil() && options.respondsTo("[]")) {
        IRubyObject rInitialCapacity = options.callMethod(context, "[]", runtime.newSymbol("initial_capacity"));
        IRubyObject rLoadFactor      = options.callMethod(context, "[]", runtime.newSymbol("load_factor"));
        int initialCapacity = !rInitialCapacity.isNil() ? RubyNumeric.num2int(rInitialCapacity.convertToInteger()) : DEFAULT_INITIAL_CAPACITY;
        float loadFactor    = !rLoadFactor.isNil() ?      (float)RubyNumeric.num2dbl(rLoadFactor.convertToFloat()) : DEFAULT_LOAD_FACTOR;
        return newCHM(initialCapacity, loadFactor);
    } else {
        return newCHM();
    }
}
 
开发者ID:ruby-concurrency,项目名称:thread_safe,代码行数:13,代码来源:JRubyCacheBackendLibrary.java

示例6: captureMessage

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
public void captureMessage(final RaiseException re) {
	try {
		IRubyObject rubyException = re.getException();
		ThreadContext context = rubyException.getRuntime().getCurrentContext();
		// JRuby-Rack internals (@see jruby/rack/capture.rb) :
		rubyException.callMethod(context, "capture");
		rubyException.callMethod(context, "store");
	} catch (Exception e) {
		rackContext.log("INFO", "failed to capture exception message", e);
	}
}
 
开发者ID:stokesdrift,项目名称:stokesdrift,代码行数:12,代码来源:RubyUtil.java

示例7: add_ruby

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
 * Adds two numbers (in practice you would implement some method in java, 
 * probably using an external library)
 * @param context ThreadContext
 * @param a probably expect RubyFixnum
 * @param b probably expect RubyFixnum
 * @return result probably RubyFixnum
 */
@JRubyMethod(name = "add")
public IRubyObject add_ruby(ThreadContext context, IRubyObject a, IRubyObject b) {
    return a.callMethod(context, "+", b);
}
 
开发者ID:jruby,项目名称:jruby-examples,代码行数:13,代码来源:RubyBar.java

示例8: sub_ruby

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
 * Subtract two numbers (in practice you would implement some method in java, 
 * probably using an external library)
 * @param context ThreadContext
 * @param a probably expect RubyFixnum
 * @param b probably expect RubyFixnum
 * @return result probably RubyFixnum
 */
@JRubyMethod(name = "subtract")
public IRubyObject sub_ruby(ThreadContext context, IRubyObject a, IRubyObject b) {
    return a.callMethod(context, "-", b);
}
 
开发者ID:jruby,项目名称:jruby-examples,代码行数:13,代码来源:RubyBar.java

示例9: div

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
 * Divide two numbers (in practice you would implement some method in java, 
 * probably using an external library)
 * @param context ThreadContext
 * @param a probably expect RubyFixnum
 * @param b probably expect RubyFixnum
 * @return result probably RubyFixnum
 */
@JRubyMethod(name = "divide")
public IRubyObject div(ThreadContext context, IRubyObject a, IRubyObject b) {
    return a.callMethod(context, "/", b);
}
 
开发者ID:jruby,项目名称:jruby-examples,代码行数:13,代码来源:RubyBar.java


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