Sha256: da46d1b933755160c8f9c03e45ddc226a9d876a21c90ee6b7e74d6c498a4a551

Contents?: true

Size: 737 Bytes

Versions: 1

Compression:

Stored size: 737 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)
    include?(other.first) || other.include?(first)
  end unless method_defined? :overlaps?

end # class Range

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.1 lib/veritas/core_ext/range.rb