--001517447fc877e6c004ac4de9b0 Content-Type: text/plain; charset=UTF-8 On Tue, Sep 6, 2011 at 11:47 PM, Intransition <transfire / gmail.com> wrote: > Is there a method out there already that does anything like this? > > [0,1,2,3,4].group(0..-2, -1) # [[0,1,2,3]. [4]] > [0,1,2,3,4].group(0, 2..3, 4..-1) # [[0], [2,3], [4]] > Here's one way, if you only want one split and your condition is not always this trivial: >> [1,2,3,4,5].partition.with_index { |e, i| i < 2 } >> [[1, 2], [3, 4, 5]] For instance: >> [1,2,3,4,5].partition { |e| e % 2 0 } [[2, 4], [1, 3, 5]] For other cases, the simplest is probably: >> ary 1,2,3,4,5] >> [ary[0], ary[2..3], ary[4..-1]] --001517447fc877e6c004ac4de9b0--