Skip to content
instance method

Kernel#readline

(?::String arg0, ?::Integer arg1, ?chomp: ::boolish) -> ::String
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.

See also #Rational #readlines #rand #require also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0