--0015174be49e36f6b604b4e08432
Content-Type: text/plain; charset=ISO-8859-1

On Dec 24, 2011 6:29 PM, "Jake S." <jakesmmrs2 / gmail.com> wrote:
>
> I'm looking for a method that takes an array and returns its elements
> grouped together in arrays of length 2, with the array at the very end
> having a length of 1 or two.
>
> For example:
> group [1,2,3,4,5,6] #[[1,2],[3,4],[5,6]]
> group ['f','o','o'] #[['f','o'],['o']]
>
> --
> Posted via http://www.ruby-forum.com/.
>

def group(ary)
  ary.each_slice(2).to_a
end

--0015174be49e36f6b604b4e08432--