18 lines
298 B
Ruby
Raw Normal View History

2016-08-18 22:11:42 +03:00
class IO
def readline_nonblock(sep = $INPUT_RECORD_SEPARATOR)
line = ""
2016-08-18 22:11:42 +03:00
buffer = ""
loop do
break if buffer == sep
read_nonblock(1, buffer)
line.concat(buffer)
end
line
2016-08-18 22:11:42 +03:00
rescue IO::WaitReadable, EOFError => e
raise e if line.empty?
line
2016-08-18 22:11:42 +03:00
end
end