Class: StringCalculator
- Inherits:
-
Object
- Object
- StringCalculator
- Defined in:
- lib/generators/turbolog/templates/lib/string_calculator.rb
Overview
lib/string_calculator.rb
Class Method Summary collapse
Class Method Details
.add(input) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/generators/turbolog/templates/lib/string_calculator.rb', line 4 def self.add(input) if input.empty? 0 else numbers = input.split(",").map { |num| num.to_i } numbers.inject(0) { |sum, number| sum + number } end end |