
Issue #19839 has been updated by baweaver (Brandon Weaver). I've made several helpers for this exact same problem, as well as a `Range#merge` in the past. I would very much be in favor of this change. Example usage from an interview problem, though I have some internal usecases which have done similar: https://gist.github.com/baweaver/5dbca4296db0651de41267c2c1267c68 The idea for this was to bold targeted segments of a `String` like: ```ruby Emboldener.new(text: "aaabbcc", targets: ["aaa","aab","bc"]).run ``` ...and have intersections merged. Granted this also brings up an interesting follow-up potential of merging ranges and if they happen to be left or right biased: ```ruby private def merge_range(a, b) return Range.new(a.begin, b.end) if a.cover?(b.begin) return Range.new(b.begin, a.end) if b.cover?(a.begin) nil end ``` In any case the `overlap?` method would be very handy to me for a number of use-cases. ---------------------------------------- Feature #19839: Need a method to check if two ranges overlap https://bugs.ruby-lang.org/issues/19839#change-104151 * Author: shouichi (Shouichi KAMIYA) * Status: Open * Priority: Normal ---------------------------------------- It would be convenient to have a method that checks if two ranges overlap. For example, ``` (0..10).overlap?(5..15) #=> true (0..10).overlap?(20..30) #=> false ``` -- https://bugs.ruby-lang.org/