From: Bryan Richardson Date: 2008-08-07T08:05:52+09:00 Subject: Re: Need help detecting overlapping ranges Crazy! I had *just* discovered the r.last lastr.last max problem when you posted this. Thanks! :) David A. Black wrote: > Here's the heavy artillery :-) > > def merge_ranges(ranges) > ranges = ranges.sort_by {|r| r.first } > *outages = ranges.shift > ranges.each do |r| > lastr = outages[-1] > if lastr.last >= r.first - 1 > outages[-1] = lastr.first..[r.last, lastr.last].max > else > outages.push(r) > end > end > outages > end -- Posted via http://www.ruby-forum.com/.