class Range
:nodoc:
def as_json(options = nil) # :nodoc:
def as_json(options = nil) # :nodoc: to_s end
def overlaps?(other)
(1..5).overlaps?(4..6) # => true
Compare two ranges and see if they overlap each other
def overlaps?(other) other.begin == self.begin || cover?(other.begin) || other.cover?(self.begin) end
def sum(identity = nil)
Optimize range sum to use arithmetic progression if a block is not given and
:nodoc:
def sum(identity = nil) if block_given? || !(first.is_a?(Integer) && last.is_a?(Integer)) super else actual_last = exclude_end? ? (last - 1) : last if actual_last >= first sum = identity || 0 sum + (actual_last - first + 1) * (actual_last + first) / 2 else identity || 0 end end end