I think you have a problem separately. If you have nvalues in dates, then you will have n-1differences between consecutive pairs, so yours avgshould be:
avg = difference.inject{ |sum, el| sum + el }.to_f / (arr.size - 1)
inject - inject(:+), :
avg = difference.inject(:+).to_f / (arr.size - 1)
map each_cons, :
dates.map(&:to_date).each_cons(2).map { |d1, d2| d1 - d2 }.inject(:+) / (dates.length - 1)
map(&:to_date), , . each_cons(2) (.. [1,2,3,4] [[1,2], [2,3], [3,4]]). map, inject(:+), .
Rational, to_f to_i, .