method
ungetbyte
v2_6_3 -
Show latest stable
- Class:
StringIO
ungetbyte(p1)public
See IO#ungetbyte
static VALUE
strio_ungetbyte(VALUE self, VALUE c)
{
struct StringIO *ptr = readable(self);
check_modifiable(ptr);
switch (TYPE(c)) {
case T_NIL:
return Qnil;
case T_FIXNUM:
case T_BIGNUM: ;
/* rb_int_modulo() not visible from exts */
VALUE v = rb_funcall(c, rb_intern("modulo"), 1, INT2FIX(256));
unsigned char cc = NUM2INT(v) & 0xFF;
c = rb_str_new((const char *)&cc, 1);
break;
default:
SafeStringValue(c);
}
const char *cp = RSTRING_PTR(c);
long cl = RSTRING_LEN(c);
if (cl == 0) return Qnil;
strio_unget_bytes(ptr, cp, cl);
RB_GC_GUARD(c);
return Qnil;
} Related methods
- Instance methods
- binmode
- bytes
- chars
- close
- close_read
- close_write
- closed?
- closed_read?
- closed_write?
- codepoints
- each
- each_byte
- each_char
- each_codepoint
- each_line
- eof
- eof?
- external_encoding
- fcntl
- fileno
- flush
- fsync
- getbyte
- getc
- gets
- initialize_copy
- internal_encoding
- isatty
- length
- lineno
- lineno=
- lines
- pid
- pos
- pos=
- putc
- read
- readlines
- reopen
- rewind
- seek
- set_encoding
- size
- string
- string=
- sync
- sync=
- tell
- truncate
- tty?
- ungetbyte
- ungetc
- write
- Class methods
- new
- open