Sha256: 136f69d4bfacd4650f618b0a599492570afb234d1c2f65793684716689bc80cc

Contents?: true

Size: 828 Bytes

Versions: 3

Compression:

Stored size: 828 Bytes

Contents

# encoding: utf-8

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

  unless method_defined?(:to_inclusive)
    # 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
  end

  unless method_defined?(:overlaps?)
    # 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
  end

end # class Range

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
axiom-0.2.0 lib/axiom/core_ext/range.rb
axiom-0.1.1 lib/axiom/core_ext/range.rb
axiom-0.1.0 lib/axiom/core_ext/range.rb