Module: RangeOperations::Pair

Defined in:
lib/range_operations/pair.rb

Class Method Summary collapse

Class Method Details

.contiguous?(a, b) ⇒ Boolean

True if the extremeties of the two ranges touch

Returns:

  • (Boolean)


10
11
12
# File 'lib/range_operations/pair.rb', line 10

def self.contiguous?(a, b)
  a && b && (a.end == b.begin || b.end == a.begin)
end

.disjoint?(a, b) ⇒ Boolean

True if the ranges do not overlap and do not touch

Returns:

  • (Boolean)


15
16
17
# File 'lib/range_operations/pair.rb', line 15

def self.disjoint?(a, b)
  a && b && !a.cover?(b) && !b.cover?(a)
end

.merge(a, b) ⇒ Object

Make a Range form a’s begin and b’s end



20
21
22
# File 'lib/range_operations/pair.rb', line 20

def self.merge(a, b)
  a.begin .. b.end
end

.overlap?(a, b) ⇒ Boolean

True if sections of the two ranges overlap

Returns:

  • (Boolean)


5
6
7
# File 'lib/range_operations/pair.rb', line 5

def self.overlap?(a, b)
  a && b && (a.cover?(b.begin) || b.cover?(a.begin))
end