Timothy Goddard
2/12/2006 10:36:00 AM
As a method without having to worry about threads you could also use:
require 'timeout'
messages = ["What are you waiting for?", "I don't have all day.", "When
I said 'take your time', I didn't mean this long!", "Hurry up and enter
a value!"]
s = nil
until s
begin
Timeout::timeout(5) do
puts "Enter a value: "
s = gets
end
rescue Timeout::Error
puts messages[rand(messages.length).to_i]
end
end