예제 #1
0
파일: RubyIconv.java 프로젝트: qmx/jruby
  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
파일: RubyIconv.java 프로젝트: qmx/jruby
  @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;
  }