require 'timeout'def count_for_five_seconds $counter = 0 begin Timeout::timeout(5) { loop { $counter += 1 } } rescue Timeout::Error puts "count to #{$counter} in 5 seconds." endendcount_for_five_secondsputs $counter