From: Max Muermann Date: 2006-08-09T11:18:10+09:00 Subject: Re: Simple looping question equire 'yaml' require 'enumerator' data = YAML::load File.read('data.yml') data.entries.sort_by{|date, *| date }.each_cons(2) do | first, second | date_first = DateTime.parse(second[0].to_s) date_second = DateTime.parse(first[0].to_s) duration = date_first - date_second miles = second[1][1] - first[1][1] miles_per_gallon = miles / first[1][0] p "The #{first[1][0]} gallons of gas purchased on #{date_first.strftime('%m/%d/%Y')} lasted #{duration.to_i} days. The mileage was #{miles_per_gallon} miles per gallon." end The key here is the each_cons coming from the enumerable mixin, which iterates the array in pairs of twos. Disclaimer: I am a German living in Australia, so if I got the date format or the miles per gallon calculation wrong, blame the non-metric system. Max