Example #1
0
 @Specialization
 public RubyArray unpack(RubyString string, RubyString format) {
   final org.jruby.RubyArray jrubyArray =
       Pack.unpack(getContext().getRuntime(), string.getBytes(), format.getBytes());
   return RubyArray.specializedFromObjects(
       getContext().getCoreLibrary().getArrayClass(), jrubyArray.toArray());
 }
Example #2
0
  @JRubyMethod(backtrace = true)
  public IRubyObject java_method(
      ThreadContext context, IRubyObject rubyName, IRubyObject argTypes) {
    String name = rubyName.asJavaString();
    RubyArray argTypesAry = argTypes.convertToArray();
    Class[] argTypesClasses = (Class[]) argTypesAry.toArray(new Class[argTypesAry.size()]);

    return getRubyMethod(name, argTypesClasses);
  }
Example #3
0
  @JRubyMethod(required = 4, rest = true, backtrace = true)
  public IRubyObject java_send(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();

    String name = args[0].asJavaString();
    RubyArray argTypesAry = args[1].convertToArray();
    int argsLen = args.length - 2;

    if (argTypesAry.size() != argsLen) {
      Class[] argTypesClasses = (Class[]) argTypesAry.toArray(new Class[argTypesAry.size()]);
      throw JavaMethod.newArgSizeMismatchError(runtime, argTypesClasses);
    }

    Class[] argTypesClasses = (Class[]) argTypesAry.toArray(new Class[argsLen]);

    Object[] argsAry = new Object[argsLen];
    for (int i = 0; i < argsLen; i++) {
      argsAry[i] = args[i + 2].toJava(argTypesClasses[i]);
    }

    JavaMethod method = new JavaMethod(runtime, getMethod(name, argTypesClasses));
    return method.invokeDirect(getObject(), argsAry);
  }
Example #4
0
  @JRubyMethod(backtrace = true)
  public IRubyObject java_send(ThreadContext context, IRubyObject rubyName, IRubyObject argTypes) {
    String name = rubyName.asJavaString();
    RubyArray argTypesAry = argTypes.convertToArray();
    Ruby runtime = context.getRuntime();

    if (argTypesAry.size() != 0) {
      Class[] argTypesClasses = (Class[]) argTypesAry.toArray(new Class[argTypesAry.size()]);
      throw JavaMethod.newArgSizeMismatchError(runtime, argTypesClasses);
    }

    JavaMethod method = new JavaMethod(runtime, getMethod(name));
    return method.invokeDirect(getObject());
  }