From: Peter Szinek Date: 2006-11-15T03:43:10+09:00 Subject: Re: Convert singel dimention array into grid Giant Cranes wrote: > Hi, > > I have been learning ruby for the past week and am completely hooked. > Most of the code I am producing is elegant (ruby's credit), although I > am having trouble elegantly converting a single dimension array with 16 > elements into a two-dimension grid [4x4]. > require 'enumerator' > @array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] result = [] @array.each_slice(4) {|s| result << s } should do the job. Cheers, Peter __ http://www.rubyrailways.com