在线文档教程
Ruby 2.4

IO::generic_readable

module IO::generic_readable

公共实例方法

getch(min: nil, time: nil) → char 显示源文件

See IO#getch.

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

getpass(prompt=nil) → string Show source

See IO#getpass.

static VALUE io_getpass(int argc, VALUE *argv, VALUE io) { VALUE str; rb_check_arity(argc, 0, 1 prompt(argc, argv, io str = str_chomp(rb_funcallv(io, id_gets, 0, 0) puts_call(io return str; }

read_nonblock(integer[, outbuf , opts]) → string Show source

与读取类似,但EOFError在字符串结尾处引发,除非传入+ exception:false +选项。

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 → fixnum Show source

See IO#readbyte.

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

readchar → string Show source

See IO#readchar.

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

readline(sep=$/) → string Show source

readline(limit) → string or nil

readline(sep, limit) → string or nil

See IO#readline.

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

readpartial(integer, outbuf) → 字符串显示源文件

类似于读取,但是EOFError在字符串结尾而不是返回nil,以及 IO#sysread。

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

sysread(integer, outbuf) → 字符串显示源文件

类似于读取,但是EOFError在字符串结尾而不是返回nil,以及 IO#sysread。

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