From: Avdi Grimm Date: 2007-02-22T04:05:53+09:00 Subject: Re: Interval relationships (Was: Re: Range#overlap?) ------=_Part_10497_33220100.1172084750379 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 2/21/07, Pit Capitain wrote: > > 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 > > Very slick! And an interesting example of Array auto-splatting (or whatever it's called...) in the inject block. Thanks! -- Avdi ------=_Part_10497_33220100.1172084750379--