Module: IO::generic_readable

Included in:
StringIO
Defined in:
ext/stringio/stringio.c

Instance Method Summary collapse

Instance Method Details

#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:

  • (String)


1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
# File 'ext/stringio/stringio.c', line 1798

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.



1162
1163
1164
1165
1166
1167
1168
# File 'ext/stringio/stringio.c', line 1162

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:

  • (String)


1147
1148
1149
1150
1151
1152
1153
# File 'ext/stringio/stringio.c', line 1147

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:

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

    Returns:

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

    Returns:

    • (String)


1460
1461
1462
1463
1464
1465
1466
# File 'ext/stringio/stringio.c', line 1460

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:

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

    Returns:

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

    Returns:

    • (String)


1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'ext/stringio/stringio.c', line 1781

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:

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

    Returns:

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

    Returns:

    • (String)


1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'ext/stringio/stringio.c', line 1781

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;
}