module SumOfNumbers

Constants

VERSION

Public Class Methods

total_num(str) click to toggle source
# File lib/sum_of_numbers.rb, line 4
def self.total_num(str)
  if (str.include?("-"))
    raise "Negative numbers are not allowed"
  else
    total = 0
    str.gsub(/[^0-9]/, "+").split('+').reject {
      |t| t.empty?
    }.each {
      |strnum| total = total + strnum.to_f
    }
    return total
  end
end