From: ara.t.howard@... Date: 2007-02-02T03:38:48+09:00 Subject: Re: skim Array two by two On Fri, 2 Feb 2007, Mickael Faivre-Macon wrote: > Hi, > > Is it possible to get 2 elements at once ? > > [1,2,3,4].each {|a,b| puts a;puts b;puts 'x'} > produces > 1, > nil > x > 2 > nil > x > 3 > nil > x > 4 > nil > x > > I'd like to get > > 1 > 2 > x > 3 > 4 > x > > Thanks ! harp:~ > cat a.rb require 'enumerator' puts %w( a b c d e ).each_cons(2){|x,y| p [x,y]} puts %w( a b c d e ).each_slice(2){|x,y| p [x,y]} harp:~ > ruby a.rb ["a", "b"] ["b", "c"] ["c", "d"] ["d", "e"] ["a", "b"] ["c", "d"] ["e", nil] -a -- we can deny everything, except that we have the possibility of being better. simply reflect on that. - the dalai lama