Avdi Grimm schrieb:
> In particular I'm looking for the most straightforward way to consolidate a
> set of intervals such that the resulting set is composed of the smallest
> number of non-contiguous, non-overlapping intervals that encompass all of
> the starting intervals. E.g.:
> 
> |---|
>   |---|
>       |---|
>              |---|
>             |------|
> 
> would become:
> 
> |---------|
>             |------|

Avdi, here's one way (based on your example above):

   def combine(intervals)
     intervals.sort.inject([]) { |result, (from, to)|
       if result.empty? or from > result.last[1]
         result << [from, to]
       elsif to > result.last[1]
         result.last[1] = to
       end
       result
     }
   end

   p combine([[0, 4], [2, 6], [6, 10], [13, 17], [12, 19]])
   # => [[0, 10], [12, 19]]

Regards,
Pit