On Wed, Sep 7, 2011 at 12:47 AM, Intransition <transfire / gmail.com> wrote:
> Is there a method out there already that does anything like this?
>
> =A0 =A0[0,1,2,3,4].group(0..-2, -1) =A0#=3D> [[0,1,2,3]. [4]]
> =A0 =A0[0,1,2,3,4].group(0, 2..3, 4..-1) =A0#=3D> [[0], [2,3], [4]]

I guess I would just do something like this:

class Array
  def group(*ranges)
     ranges.map { |r| values_at(r) }
   end
end

>> [0,1,2,3,4].group(0..-2, -1)
=3D> [[0, 1, 2, 3], [4]]
>> [0,1,2,3,4].group(0, 2..3, 4..-1)  #=3D> [[0], [2,3], [4]]
=3D> [[0], [2, 3], [4]]