Method: StringIO#putc

Defined in:
stringio.c

#putc(obj) ⇒ Object

See IO#putc.

Returns:

  • (Object)


1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'stringio.c', line 1232

static VALUE
strio_putc(VALUE self, VALUE ch)
{
    struct StringIO *ptr = writable(self);
    int c = NUM2CHR(ch);
    long olen;

    check_modifiable(ptr);
    olen = RSTRING_LEN(ptr->string);
    if (ptr->flags & FMODE_APPEND) {
	ptr->pos = olen;
    }
    strio_extend(ptr, ptr->pos, 1);
    RSTRING_PTR(ptr->string)[ptr->pos++] = c;
    OBJ_INFECT(ptr->string, self);
    return ch;
}