From: "David A. Black" Date: 2009-07-29T19:56:34+09:00 Subject: Re: previous value in array block Hi -- On Wed, 29 Jul 2009, Xavier Noria wrote: > each_cons seems natural here: > > require 'enumerator' > > a = [1, 3, 3, 2] > b = a[0, 1] > > a.each_cons(2) { |x, y| b << y - x } Here's a 1.9 way, probably guilty of gross wasteage (by creating an extra new array) but kind of cool: [0,*a].each_cons(2).map {|x,y| y - x } David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Q: What's the best way to get a really solid knowledge of Ruby? A: Come to our Ruby training in Edison, New Jersey, September 14-17! Instructors: David A. Black and Erik Kastner More info and registration: http://rubyurl.com/vmzN