James Gray
12/14/2005 2:22:00 PM
On Dec 14, 2005, at 8:09 AM, Steve Litt wrote:
> #!/usr/bin/ruby
> b4 = Time.new
> sleep(3)
> after = Time.new
> interval = after.to_i - b4.to_i
You can just subtract normally. Time knows what to do:
interval = after - b4
> print "Started at ", b4.asctime, ", ended at ", after.asctime
> print "\n Interval is ", interval.to_s, ".\n"
It's a good idea to get into the habit of using interpolation with
Ruby. That let's Ruby take care of stringifying your values. We can
also lose those \n characters:
puts "Started at #{b4} and ended at #{after}."
puts "Interval is #{interval}."
James Edward Gray II