From: Jason Lillywhite Date: 2009-07-29T12:39:26+09:00 Subject: previous value in array block Is this a good way to use a previous value in an array block? I want to subtract the item(i) from item(i-1) of the array, a and return a new array of the results. Below is my attempt. a = [1,3,3,2] prev_item = 0 b = [] a.each do |item| b << item - prev_item prev_item = item end puts b => 1,2,0,-1 I'm thinking there must be a more elegant way of doing this. thank you! -- Posted via http://www.ruby-forum.com/.