How to timeout gets.chomp
You can use the timeout
standard library
require "timeout"
puts "How are you?"
begin
Timeout::timeout 5 do
ans = gets.chomp
end
rescue Timeout::Error
ans = nil
end
puts (ans || "User did not respond")
Read more about the library http://www.ruby-doc.org/stdlib-2.1.5/libdoc/timeout/rdoc/Timeout.html