number of minutes you want to count down. : downto « Statement « Ruby






number of minutes you want to count down.


def timer( start )
  puts "Minutes: " + start.to_s
  start_time = Time.now
  puts start_time.strftime("Start to_time: %I:%M:%S %p")
  start.downto(1) { |i| sleep 60 }
  end_time = Time.now
  print end_time.strftime("Elapsed time: %I:%M:%S %p")
end

timer 10

 








Related examples in the same category

1.A downto iterator, which starts at a higher number and loops to a lower number.
2.Both the Integer and Date classes have downto methods
3.downto method with integer
4.downto with block