Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Range#overlaps? for beginless ranges #44757

Merged
merged 1 commit into from Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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