method
overlaps?
v3.2.13 -
Show latest stable
- Class:
Range
overlaps?(other)public
Compare two ranges and see if they overlap each other
(1..5).overlaps?(4..6) # => true (1..5).overlaps?(7..9) # => false
3Notes
Take care with time ranges
Trying this in the console:
(1.day.from_now..5.days.from_now).overlaps?(5.days.from_now..10.days.from_now)
will blow up...
It's fine with Dates though:
(1.day.from_now.to_date..5.days.from_now.to_date).overlaps?(5.days.from_now.to_date..10.days.from_now.to_date) # => true
Adjacency
Just for completeness (it should behave like this), comparing ranges that start and end with the same value will overlap, e.g.
(1..5).overlaps?(5..10) # => true