diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb index f753607f8bbb9..c286988d13a25 100644 --- a/activesupport/lib/active_support/core_ext/range/overlaps.rb +++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb @@ -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 diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index cd6ed6c4753ef..9ce98858dc7d1 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -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