Example #1
0
  @JRubyMethod(name = "putc", required = 1)
  public IRubyObject putc(IRubyObject ch) {
    checkWritable();
    byte c = RubyNumeric.num2chr(ch);
    int olen;

    checkModifiable();

    olen = ptr.string.size();
    if ((ptr.flags & OpenFile.APPEND) != 0) {
      ptr.pos = olen;
    }
    strioExtend(ptr.pos, 1);
    ptr.string.getByteList().set(ptr.pos++, c);
    ptr.string.infectBy(this);
    return ch;
  }
  @JRubyMethod(name = "putc", required = 1)
  @Override
  public IRubyObject putc(IRubyObject obj) {
    checkWritable();
    byte c = RubyNumeric.num2chr(obj);
    checkFrozen();

    data.internal.modify();
    ByteList bytes = data.internal.getByteList();
    if (data.modes.isAppendable()) {
      data.pos = bytes.length();
      bytes.append(c);
    } else {
      if (isEndOfString()) bytes.length((int) data.pos + 1);

      bytes.set((int) data.pos, c);
      data.pos++;
    }

    return obj;
  }
Example #3
0
  @JRubyMethod(name = "putc", required = 1)
  public IRubyObject putc(IRubyObject obj) {
    checkWritable();
    byte c = RubyNumeric.num2chr(obj);
    checkFrozen();

    internal.modify();
    ByteList bytes = internal.getByteList();
    if (modes.isAppendable()) {
      pos = bytes.length();
      bytes.append(c);
    } else {
      if (pos >= bytes.length()) {
        bytes.length((int) pos + 1);
      }

      bytes.set((int) pos, c);
      pos++;
    }

    return obj;
  }