Sha256: 864a4761db284a8f6b2d347835c10aafd09a043bab359a2e292d4cb6a9e74743

Contents?: true

Size: 733 Bytes

Versions: 2

Compression:

Stored size: 733 Bytes

Contents

# Extend Range with methods to normalize and find overlapping ranges
class Range

  # Returns an inclusive Range
  #
  # @example
  #   inclusive = range.to_inclusive
  #
  # @return [Range]
  #
  # @api public
  def to_inclusive
    if exclude_end?
      self.class.new(first, last.pred)
    else
      self
    end
  end unless method_defined? :to_inclusive

  # Compare the range with another range to see if they overlap
  #
  # @example
  #   range.overlaps?(other)  # => true or false
  #
  # @param [Range] other
  #   the other Range to compare with
  #
  # @return [Boolean]
  #
  # @api public
  def overlaps?(other)
    cover?(other.first) || other.cover?(first)
  end unless method_defined? :overlaps?

end # class Range

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
veritas-0.0.3 lib/veritas/core_ext/range.rb
veritas-0.0.2 lib/veritas/core_ext/range.rb