@JRubyMethod(name = "puts", rest = true)
  @Override
  public IRubyObject puts(ThreadContext context, IRubyObject[] args) {
    checkWritable();

    // FIXME: the code below is a copy of RubyIO.puts,
    // and we should avoid copy-paste.

    if (args.length == 0) {
      callMethod(context, "write", RubyString.newStringShared(getRuntime(), NEWLINE));
      return getRuntime().getNil();
    }

    for (int i = 0; i < args.length; i++) {
      RubyString line;

      if (args[i].isNil()) {
        line = getRuntime().newString("nil");
      } else {
        IRubyObject tmp = args[i].checkArrayType();
        if (!tmp.isNil()) {
          RubyArray arr = (RubyArray) tmp;
          if (getRuntime().isInspecting(arr)) {
            line = getRuntime().newString("[...]");
          } else {
            inspectPuts(context, arr);
            continue;
          }
        } else {
          if (args[i] instanceof RubyString) {
            line = (RubyString) args[i];
          } else {
            line = args[i].asString();
          }
        }
      }

      callMethod(context, "write", line);

      if (!line.getByteList().endsWith(NEWLINE)) {
        callMethod(context, "write", RubyString.newStringShared(getRuntime(), NEWLINE));
      }
    }
    return getRuntime().getNil();
  }