Module: IO::generic_readable
- Included in:
- StringIO
- Defined in:
- docs/io.rb,
ext/stringio/stringio.c
Instance Method Summary collapse
-
#read_nonblock(integer[, outbuf [, opts]]) ⇒ String
Similar to #read, but raises
EOFErrorat end of string unless the exception: false option is passed in. -
#readbyte ⇒ Object
Like
getbyte, but raises an exception if already at end-of-stream; see Byte IO. -
#readchar ⇒ String
Like
getc, but raises an exception if already at end-of-stream; see Character IO. -
#readline(*args) ⇒ Object
Reads a line as with IO#gets, but raises EOFError if already at end-of-file; see Line IO.
-
#readpartial(*args) ⇒ Object
Similar to #read, but raises
EOFErrorat end of string instead of returningnil, as well as IO#sysread does. -
#sysread(*args) ⇒ Object
Similar to #read, but raises
EOFErrorat end of string instead of returningnil, as well as IO#sysread does.
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.
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 |
# File 'ext/stringio/stringio.c', line 1698 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; } |
#readbyte ⇒ Object
Like getbyte, but raises an exception if already at end-of-stream; see Byte IO.
1058 1059 1060 1061 1062 1063 1064 |
# File 'ext/stringio/stringio.c', line 1058 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; } |
#readchar ⇒ String
Like getc, but raises an exception if already at end-of-stream; see Character IO.
1043 1044 1045 1046 1047 1048 1049 |
# File 'ext/stringio/stringio.c', line 1043 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.
1359 1360 1361 1362 1363 1364 1365 |
# File 'ext/stringio/stringio.c', line 1359 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.
1681 1682 1683 1684 1685 1686 1687 1688 1689 |
# File 'ext/stringio/stringio.c', line 1681 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.
1681 1682 1683 1684 1685 1686 1687 1688 1689 |
# File 'ext/stringio/stringio.c', line 1681 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; } |