Skip to content

Instantly share code, notes, and snippets.

@vgarro
Created June 2, 2022 00:15
Show Gist options
  • Save vgarro/9279c4e3ae07e25205782ac43b62ce11 to your computer and use it in GitHub Desktop.
Save vgarro/9279c4e3ae07e25205782ac43b62ce11 to your computer and use it in GitHub Desktop.
Single Responsibility coding challenge
class AritmeticCalculation
attr_reader :math_operation, :numbers
def initialize(math_operation:, numbers:)
math_operation = math_operation
numbers = numbers || []
end
def run_math
case math_operation
when "sum"
puts "the operation will be SUM"
numbers.inject(&:+)
when "subs"
puts "the operation will be SUBTRACTION"
numbers.inject(&:-)
when "div"
puts "the operation will be DIVISION"
numbers[0] / numbers[1]
when "mult"
puts "the operation will be MULTIPLICATION"
numbers.inject(&:*)
else
raise "Invalid Operation"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment