diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/range/overlaps.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/overlaps.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb new file mode 100644 index 0000000000..f753607f8b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class Range + # Compare two ranges and see if they overlap each other + # (1..5).overlaps?(4..6) # => true + # (1..5).overlaps?(7..9) # => false + def overlaps?(other) + cover?(other.first) || other.cover?(first) + end +end |