From: Chris Blair Date: 2006-11-16T16:47:45+09:00 Subject: Re: Splitting an array into quads and putting them back together again. ------=_Part_70369_14110990.1163663229858 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/12/06, Martin DeMello wrote: > > require 'enumerator' > > class Array > def |(other) > self.zip(other).map {|a,b| a+b} > end > > def /(other) > self + other > end > end > > a1 = [[1,2],[5,6]] > b1 = [[3,4],[7,8]] > a2 = [[9,10],[13,14]] > b2 = [[11,12],[15,16]] > > p (a1|b1)/(a2|b2) > > class Array > def shape(cols) > enum_slice(cols).map {|i| i.inject {|j, k| j|k}}.inject {|a, i| a/i} > end > end > > p [a1, b1, a2, b2].shape(2) > > Thanks! I don't quite understand the code, right now, but it does work exactly how I wanted it. Sorry for the delay in responding, I haven't had access to the internet for a little while. Thanks again! ------=_Part_70369_14110990.1163663229858--