From: Robert Klemme Date: 2008-02-05T01:19:43+09:00 Subject: Re: convert array to array-of-arrays? 2008/2/4, Chris Hulan : > On Feb 4, 10:45 am, Phlip wrote: > > Given [1, 2, 3, 4], what's the most Rubiesque way to get [[1, 2], [3, 4]]? > > > > I had figured a variation on Array#transpose would be available, but I can't > > find one! > > have a look at enum.partition (http://ruby-doc.org/core/classes/ > Enumerable.html#M003161) Not sure what the OP wants, but AFAIK #partition only ever returns two partitions. If the task is to combine consecutive elements #each_slice works well: $ irb -r enumerator irb(main):001:0> [1, 2, 3, 4].to_enum(:each_slice, 2).to_a => [[1, 2], [3, 4]] irb(main):002:0> Kind regards robert -- use.inject do |as, often| as.you_can - without end