Method: Kernel#readline

Defined in:
io.c

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

Equivalent to method Kernel#gets, except that it raises an exception if called at end-of-stream:

$ cat t.txt | ruby -e "p readlines; readline"
["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
in `readline': end of file reached (EOFError)

Optional keyword argument chomp specifies whether line separators are to be omitted.

Overloads:

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

    Returns:

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

    Returns:

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

    Returns:



10445
10446
10447
10448
10449
10450
10451
10452
# File 'io.c', line 10445

static VALUE
rb_f_readline(int argc, VALUE *argv, VALUE recv)
{
    if (recv == argf) {
        return argf_readline(argc, argv, argf);
    }
    return forward(argf, rb_intern("readline"), argc, argv);
}