Module: IO::generic_readable

Included in:
StringIO
Defined in:
ext/stringio/stringio.c,
ext/io/console/console.c

Instance Method Summary collapse

Instance Method Details

#getch(min: nil, time: nil, intr: nil) ⇒ String

See IO#getch.

Returns:



1664
1665
1666
1667
1668
# File 'ext/io/console/console.c', line 1664

static VALUE
io_getch(int argc, VALUE *argv, VALUE io)
{
    return rb_funcallv(io, id_getc, argc, argv);
}

#getpass(prompt = nil) ⇒ String

See IO#getpass.

Returns:



1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
# File 'ext/io/console/console.c', line 1747

static VALUE
io_getpass(int argc, VALUE *argv, VALUE io)
{
    VALUE str;

    rb_check_arity(argc, 0, 1);
    prompt(argc, argv, io);
    rb_check_funcall(io, id_flush, 0, 0);
    str = rb_ensure(gets_call, io, puts_call, io);
    return str_chomp(str);
}

#read_nonblock(integer[, outbuf [, opts]]) ⇒ String

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

Returns:



1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
# File 'ext/stringio/stringio.c', line 1678

static VALUE
strio_read_nonblock(int argc, VALUE *argv, VALUE self)
{
    VALUE opts = Qnil, val;

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

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

    val = strio_read(argc, argv, self);
    if (NIL_P(val)) {
	if (!NIL_P(opts) &&
	      rb_hash_lookup2(opts, sym_exception, Qundef) == Qfalse)
	    return Qnil;
	else
	    rb_eof_error();
    }

    return val;
}

#readbyteObject

Like getbyte, but raises an exception if already at end-of-stream; see Byte IO.



1043
1044
1045
1046
1047
1048
1049
# File 'ext/stringio/stringio.c', line 1043

static VALUE
strio_readbyte(VALUE self)
{
    VALUE c = rb_funcallv(self, rb_intern("getbyte"), 0, 0);
    if (NIL_P(c)) rb_eof_error();
    return c;
}

#readcharString

Like getc, but raises an exception if already at end-of-stream; see Character IO.

Returns:



1028
1029
1030
1031
1032
1033
1034
# File 'ext/stringio/stringio.c', line 1028

static VALUE
strio_readchar(VALUE self)
{
    VALUE c = rb_funcallv(self, rb_intern("getc"), 0, 0);
    if (NIL_P(c)) rb_eof_error();
    return c;
}

#readline(sep = $/, chomp: false) ⇒ String #readline(limit, chomp: false) ⇒ String #readline(sep, limit, chomp: false) ⇒ String

Reads a line as with IO#gets, but raises EOFError if already at end-of-file; see Line IO.

Overloads:

  • #readline(sep = $/, chomp: false) ⇒ String

    Returns:

  • #readline(limit, chomp: false) ⇒ String

    Returns:

  • #readline(sep, limit, chomp: false) ⇒ String

    Returns:



1343
1344
1345
1346
1347
1348
1349
# File 'ext/stringio/stringio.c', line 1343

static VALUE
strio_readline(int argc, VALUE *argv, VALUE self)
{
    VALUE line = rb_funcallv_kw(self, rb_intern("gets"), argc, argv, RB_PASS_CALLED_KEYWORDS);
    if (NIL_P(line)) rb_eof_error();
    return line;
}

#sysread(integer[, outbuf]) ⇒ String #readpartial(integer[, outbuf]) ⇒ String

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

Overloads:



1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'ext/stringio/stringio.c', line 1661

static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
    VALUE val = rb_funcallv_kw(self, rb_intern("read"), argc, argv, RB_PASS_CALLED_KEYWORDS);
    if (NIL_P(val)) {
	rb_eof_error();
    }
    return val;
}

#sysread(integer[, outbuf]) ⇒ String #readpartial(integer[, outbuf]) ⇒ String

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

Overloads:



1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'ext/stringio/stringio.c', line 1661

static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
    VALUE val = rb_funcallv_kw(self, rb_intern("read"), argc, argv, RB_PASS_CALLED_KEYWORDS);
    if (NIL_P(val)) {
	rb_eof_error();
    }
    return val;
}