module IO::generic_readable

Public Instance Methods

getch(min: nil, time: nil) → char Show source
static VALUE
io_getch(int argc, VALUE *argv, VALUE io)
{
    return rb_funcall2(io, rb_intern("getc"), argc, argv);
}

See IO#getch.

read_nonblock(integer[, outbuf [, opts]]) → string Show source
static VALUE
strio_read_nonblock(int argc, VALUE *argv, VALUE self)
{
    VALUE opts = Qnil, val;
    int no_exception = 0;

    rb_scan_args(argc, argv, "11:", NULL, NULL, &opts);

    if (!NIL_P(opts)) {
        argc--;

        if (Qfalse == rb_hash_aref(opts, sym_exception))
            no_exception = 1;
    }

    val = strio_read(argc, argv, self);
    if (NIL_P(val)) {
        if (no_exception)
            return Qnil;
        else
            rb_eof_error();
    }

    return val;
}

Similar to read, but raises EOFError at end of string unless the +exception: false+ option is passed in.

readbyte → fixnum Show source
static VALUE
strio_readbyte(VALUE self)
{
    VALUE c = rb_funcall2(self, rb_intern("getbyte"), 0, 0);
    if (NIL_P(c)) rb_eof_error();
    return c;
}

See IO#readbyte.

readchar → string Show source
static VALUE
strio_readchar(VALUE self)
{
    VALUE c = rb_funcall2(self, rb_intern("getc"), 0, 0);
    if (NIL_P(c)) rb_eof_error();
    return c;
}

See IO#readchar.

readline(sep=$/) → string Show source
readline(limit) → string or nil
readline(sep, limit) → string or nil
static VALUE
strio_readline(int argc, VALUE *argv, VALUE self)
{
    VALUE line = rb_funcall2(self, rb_intern("gets"), argc, argv);
    if (NIL_P(line)) rb_eof_error();
    return line;
}

See IO#readline.

readpartial(integer[, outbuf]) → string Show source
static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
    VALUE val = rb_funcall2(self, rb_intern("read"), argc, argv);
    if (NIL_P(val)) {
        rb_eof_error();
    }
    return val;
}

Similar to read, but raises EOFError at end of string instead of returning nil, as well as IO#sysread does.

sysread(integer[, outbuf]) → string Show source
static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
    VALUE val = rb_funcall2(self, rb_intern("read"), argc, argv);
    if (NIL_P(val)) {
        rb_eof_error();
    }
    return val;
}

Similar to read, but raises EOFError at end of string instead of returning nil, as well as IO#sysread does.

Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.