RosettaCodeData/Task/Keyboard-input-Flush-the-keyboard-buffer/Ruby/keyboard-input-flush-the-keyboard-buffer-4.rb

10 lines
226 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# Demonstration: discard input, then input a line from user.
puts 'Type anything for 2 seconds.'
sleep 2
$stdin.discard_input
print 'Enter a line? '
if line = $stdin.gets
then print 'Got line. ', line
else puts 'No line!'
end