如何 运行 .gets 但在 Ruby 一定延迟后继续 运行ning 程序

How to Run .gets but Continue Running Program after a certain delay in Ruby

我想知道如何才能 运行 .gets 但在一定延迟后继续 运行 程序。

例如:

variable=gets.chomp
#somehow continue running program to do for example:
#after a delay (sleep 10)
puts "Hello? Are you still here? The program will timeout in 10 seconds."
#asks for input again
puts "Please enter ..."
variable=gets.chomp

感谢您的宝贵时间。

require 'timeout'
print "Input something within 10 seconds: "
begin
  foo = Timeout::timeout(10) {
    gets.chomp
  }
  puts "You said #{foo}"
rescue Timeout::Error
  puts
  puts "You are too late."
end