Method: StringIO#putc

Defined in:
ext/stringio/stringio.c

#putc(obj) ⇒ Object

See IO#putc.

Returns:

  • (Object)


1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
# File 'ext/stringio/stringio.c', line 1486

static VALUE
strio_putc(VALUE self, VALUE ch)
{
    struct StringIO *ptr = writable(self);
    VALUE str;

    check_modifiable(ptr);
    if (RB_TYPE_P(ch, T_STRING)) {
  str = rb_str_substr(ch, 0, 1);
    }
    else {
  char c = NUM2CHR(ch);
  str = rb_str_new(&c, 1);
    }
    strio_write(self, str);
    return ch;
}