Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/axiom/core_ext/range.rb

Overview

Extend Range with methods to normalize and find overlapping ranges

Instance Method Summary collapse

Instance Method Details

#overlaps?(other) ⇒ Boolean

Compare the range with another range to see if they overlap

Examples:

range.overlaps?(other)  # => true or false

Parameters:

  • other (Range)

    the other Range to compare with

Returns:

  • (Boolean)


36
37
38
# File 'lib/axiom/core_ext/range.rb', line 36

def overlaps?(other)
  cover?(other.first) || other.cover?(first)
end

#to_inclusiveRange

Returns an inclusive Range

Examples:

inclusive = range.to_inclusive

Returns:



15
16
17
18
19
20
21
# File 'lib/axiom/core_ext/range.rb', line 15

def to_inclusive
  if exclude_end?
    self.class.new(first, last.pred)
  else
    self
  end
end