Flowdock
method

overlaps?

Importance_2
v3.0.9 - Show latest stable - 2 notes - 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
Show source
Register or log in to add new notes.
November 13, 2013 - (v3.2.13)
0 thanks

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
November 13, 2013 - (v3.2.13)
0 thanks

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