class Range

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