class Range

:nodoc:

def _empty_range?(b, e, excl)

def _empty_range?(b, e, excl)
  return false if b.nil? || e.nil?
  comp = b <=> e
  comp.nil? || comp > 0 || (comp == 0 && excl)
end

def as_json(options = nil) # :nodoc:

:nodoc:
def as_json(options = nil) # :nodoc:
  to_s
end

def overlap?(other)

def overlap?(other)
  raise TypeError unless other.is_a? Range
  self_begin = self.begin
  other_end = other.end
  other_excl = other.exclude_end?
  return false if _empty_range?(self_begin, other_end, other_excl)
  other_begin = other.begin
  self_end = self.end
  self_excl = self.exclude_end?
  return false if _empty_range?(other_begin, self_end, self_excl)
  return true if self_begin == other_begin
  return false if _empty_range?(self_begin, self_end, self_excl)
  return false if _empty_range?(other_begin, other_end, other_excl)
  true
end

def sum(initial_value = 0)

we have a range of numeric values.
Optimize range sum to use arithmetic progression if a block is not given and
:nodoc:
def sum(initial_value = 0)
  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 = initial_value || 0
      sum + (actual_last - first + 1) * (actual_last + first) / 2
    else
      initial_value || 0
    end
  end
end