I have an array of objects and I would like to group them based on the difference between the attributes of 2 adjacent elements. The array is already sorted by that attribute. F
array = [1, 3, 6, 9, 10] prev = array[0] p array.slice_before{|el| prev,el = el,prev; prev-el > 2}.to_a # => [[1, 3], [6], [9, 10]]