Development Ruby

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."
  end
end
count_for_five_seconds
puts $counter