Method: IO#putc
- Defined in:
- io.c
permalink #putc(object) ⇒ Object
Writes a character to the stream. See Character IO.
If object
is numeric, converts to integer if necessary, then writes the character whose code is the least significant byte; if object
is a string, writes the first character:
$stdout.putc "A"
$stdout.putc 65
Output:
AA
8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 |
# File 'io.c', line 8837
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;
}
|