Skip to content

Commit

Permalink
Merge pull request #44757 from donny741/fix-overlaps-for-beginless-range
Browse files Browse the repository at this point in the history
Fix `Range#overlaps?` for beginless ranges
  • Loading branch information
tenderlove authored and rafaelfranca committed Mar 23, 2022
1 parent f0cfc60 commit bad2c97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -5,6 +5,6 @@ class Range
# (1..5).overlaps?(4..6) # => true
# (1..5).overlaps?(7..9) # => false
def overlaps?(other)
cover?(other.first) || other.cover?(first)
other.begin == self.begin || cover?(other.begin) || other.cover?(self.begin)
end
end
8 changes: 8 additions & 0 deletions activesupport/test/core_ext/range_ext_test.rb
Expand Up @@ -65,6 +65,14 @@ def test_overlaps_first_exclusive
assert_not (5..10).overlaps?(1...5)
end

def test_overlaps_with_beginless_range
assert((1..5).overlaps?(..10))
end

def test_overlaps_with_two_beginless_ranges
assert((..5).overlaps?(..10))
end

def test_should_include_identical_inclusive
assert((1..10).include?(1..10))
end
Expand Down

0 comments on commit bad2c97

Please sign in to comment.