Method: IO#putc
- Defined in:
- io.c
#putc(obj) ⇒ Object
If obj is Numeric, write the character whose code is the least-significant byte of obj. If obj is String, write the first character of obj to ios. Otherwise, raise TypeError.
$stdout.putc "A"
$stdout.putc 65
produces:
AA
7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 |
# File 'io.c', line 7782
static VALUE
rb_io_putc(VALUE io, VALUE ch)
{
VALUE str;
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);
}
rb_io_write(io, str);
return ch;
}
|