class Range

:nodoc:

def as_json(options = nil) #:nodoc:

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

def each_with_time_with_zone(&block)

def each_with_time_with_zone(&block)
  ensure_iteration_allowed
  each_without_time_with_zone(&block)
end

def ensure_iteration_allowed

def ensure_iteration_allowed
  if first.is_a?(Time)
    raise TypeError, "can't iterate from #{first.class}"
  end
end

def include_with_range?(value)

(5..9).include?(11) # => false
('a'..'f').include?('c') # => true
The native Range#include? behavior is untouched.

(1..5).include?(2..6) # => false
(1..5).include?(2..3) # => true
(1..5).include?(1..5) # => true
Extends the default Range#include? to support range comparisons.
def include_with_range?(value)
  if value.is_a?(::Range)
    # 1...10 includes 1..9 but it does not include 1..10.
    operator = exclude_end? && !value.exclude_end? ? :< : :<=
    include_without_range?(value.first) && value.last.send(operator, last)
  else
    include_without_range?(value)
  end
end

def overlaps?(other)

(1..5).overlaps?(7..9) # => false
(1..5).overlaps?(4..6) # => true
Compare two ranges and see if they overlap each other
def overlaps?(other)
  cover?(other.first) || other.cover?(first)
end

def step_with_time_with_zone(n = 1, &block)

def step_with_time_with_zone(n = 1, &block)
  ensure_iteration_allowed
  step_without_time_with_zone(n, &block)
end

def sum(identity = 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(identity = 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
      (actual_last - first + 1) * (actual_last + first) / 2
    else
      identity
    end
  end
end

def to_formatted_s(format = :default)

(1..100).to_formatted_s # => "1..100"

Gives a human readable format of the range.
def to_formatted_s(format = :default)
  if formatter = RANGE_FORMATS[format]
    formatter.call(first, last)
  else
    to_default_s
  end
end