# --> Base method def sum(rng) x = rng.exclude_end? ? rng.last-1 : rng.last return ((x-rng.first+1)*(rng.first + x)/2.0).to_i end # --> Range class extension class Range def sum x = exclude_end? ? last-1 : last return ((x-first+1)*(first + x)/2.0).to_i end end