Пример #1
0
  public static RubyArray convertWithArgs(
      ThreadContext context, IRubyObject recv, IRubyObject[] args, String function) {
    assert args.length >= 2;

    RubyArray array = context.getRuntime().newArray(args.length - 2);
    RubyIconv iconv = newIconv(context, recv, args[0], args[1]);

    try {
      for (int i = 2; i < args.length; i++) {
        array.append(iconv.iconv(args[i]));
      }
    } finally {
      iconv.close();
    }

    return array;
  }
Пример #2
0
  @JRubyMethod(required = 2, meta = true)
  public static IRubyObject open(
      ThreadContext context, IRubyObject recv, IRubyObject to, IRubyObject from, Block block) {
    Ruby runtime = context.getRuntime();

    RubyIconv iconv = newIconv(context, recv, to, from);

    if (!block.isGiven()) return iconv;

    IRubyObject result = runtime.getNil();
    try {
      result = block.yield(context, iconv);
    } finally {
      iconv.close();
    }

    return result;
  }