old_array.each_cons(2).map{|x, y| y - x}
Enumerable#each_cons , called with a block size of 2, but without a block, returns an Enumerator that will old_array over each pair of consecutive elements in old_array . Then we just use map to do the subtraction for each pair.
source share