From rogerpack2005 at gmail.com Tue Jun 10 14:12:21 2008 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 10 Jun 2008 11:12:21 -0700 (PDT) Subject: [Facets] Array#split_to_chunks Message-ID: <0eb60987-1114-46ef-ae2a-6caf9a599c5a@q27g2000prf.googlegroups.com> Here's one: useful? :) -R class Array =begin #doc_test This function splits an array into multiple 'sub array's >> [1,2,3].split_to_chunks 2 => [[1, 2], [3]] >> [1,2,3].split_to_chunks 1 => [[1], [2], [3]] >> [1,2,3].split_to_chunks 3 => [[1, 2, 3]] =end def split_to_chunks this_big_of_chunks location = 0 outgoing = [] while location < self.length outgoing << self[location..(location+this_big_of_chunks-1)] location += this_big_of_chunks end outgoing end end From rogerpack2005 at gmail.com Tue Jun 10 14:15:50 2008 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 10 Jun 2008 11:15:50 -0700 (PDT) Subject: [Facets] Array#split_to_chunks In-Reply-To: <0eb60987-1114-46ef-ae2a-6caf9a599c5a@q27g2000prf.googlegroups.com> References: <0eb60987-1114-46ef-ae2a-6caf9a599c5a@q27g2000prf.googlegroups.com> Message-ID: <560c5a52-9102-4225-9149-da431ddc58aa@c19g2000prf.googlegroups.com> heh. Just found this >> [1,2,3].in_groups_of 2, false => [[1, 2], [3]] I'm really lacking on ri foo. -R