2016-08-18 22:11:42 +03:00
|
|
|
class IO
|
|
|
|
def readline_nonblock(sep = $INPUT_RECORD_SEPARATOR)
|
2017-04-20 04:47:03 +02:00
|
|
|
line = ""
|
2016-08-18 22:11:42 +03:00
|
|
|
buffer = ""
|
2017-04-20 04:47:03 +02:00
|
|
|
|
|
|
|
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
|
2017-04-20 04:47:03 +02:00
|
|
|
raise e if line.empty?
|
|
|
|
line
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|