Ejemplo n.º 1
0
 @JRubyMethod
 public static IRubyObject to_java(ThreadContext context, IRubyObject fromObject) {
   if (fromObject instanceof RubyArray) {
     return context
         .runtime
         .getJavaSupport()
         .getObjectJavaClass()
         .javaArrayFromRubyArray(context, fromObject);
   } else {
     return Java.getInstance(context.runtime, fromObject.toJava(Object.class));
   }
 }
Ejemplo n.º 2
0
  @JRubyMethod
  public static IRubyObject to_java(
      ThreadContext context, IRubyObject fromObject, IRubyObject type) {
    if (type.isNil()) {
      return to_java(context, fromObject);
    }

    Ruby runtime = context.runtime;
    JavaClass targetType = getTargetType(context, runtime, type);

    if (fromObject instanceof RubyArray) {
      return targetType.javaArrayFromRubyArray(context, fromObject);
    } else {
      return Java.getInstance(runtime, fromObject.toJava(targetType.javaClass()));
    }
  }