本文整理汇总了Java中org.jruby.runtime.builtin.IRubyObject.toJava方法的典型用法代码示例。如果您正苦于以下问题:Java IRubyObject.toJava方法的具体用法?Java IRubyObject.toJava怎么用?Java IRubyObject.toJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.runtime.builtin.IRubyObject
的用法示例。
在下文中一共展示了IRubyObject.toJava方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enter
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
@Override
public Object enter( String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments ) throws NoSuchMethodException, ParsingException, ExecutionException
{
entryPointName = toRubyStyle( entryPointName );
Ruby rubyRuntime = getRubyRuntime( executionContext );
// Note that we're using the shared compilerRuntime to do the
// conversions, so that we can cache Java proxies. It's very, very
// slow if we have to generate them on the fly every time!
IRubyObject[] rubyArguments = JavaUtil.convertJavaArrayToRuby( compilerRuntime, arguments );
try
{
IRubyObject value = rubyRuntime.getTopSelf().callMethod( rubyRuntime.getCurrentContext(), entryPointName, rubyArguments );
return value.toJava( Object.class );
}
catch( RaiseException x )
{
throw createExecutionException( x );
}
finally
{
rubyRuntime.getOut().flush();
rubyRuntime.getErr().flush();
}
}
示例2: compare
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
* This calls to the static method compare of DataByteArray. Given two DataByteArrays, it will call it
* on the underlying bytes.
*
* @param context the context the method is being executed in
* @param self an class which contains metadata on the calling class (required for static Ruby methods)
* @param arg1 a RubyDataByteArray or byte array to compare
* @param arg2 a RubyDataByteArray or byte array to compare
* @return the Fixnum result of comparing arg1 and arg2's bytes
*/
@JRubyMethod
public static RubyFixnum compare(ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
byte[] buf1, buf2;
if (arg1 instanceof RubyDataByteArray) {
buf1 = ((RubyDataByteArray)arg1).getDBA().get();
} else {
buf1 = (byte[])arg1.toJava(byte[].class);
}
if (arg2 instanceof RubyDataByteArray) {
buf2 = ((RubyDataByteArray)arg2).getDBA().get();
} else {
buf2 = (byte[])arg2.toJava(byte[].class);
}
return RubyFixnum.newFixnum(context.getRuntime(), DataByteArray.compare(buf1, buf2));
}