I'm learning Ruby and as part of the practice, I have implemented a simple quiz app. Its pseudocode is like this
for i in 0..questions.length - 1 do
puts questions[i]
$answer = gets.chomp
if $answer == answers[i]
correct += 1
end
end
timer_thread = Thread.new do
while $answer == nil
(1..5).each do |number|
sleep(1)
number
if number == 5
puts "Timer out"
end
break if ($answer != nil)
end
end
end
What I want is to add a timer of let's say 30 seconds, it should move to the next question and that question should be considered incorrect. I came to know about Time.now but am not sure how I can go about adding it to my program.
Any pointers, please?