Created
June 2, 2022 00:15
-
-
Save vgarro/9279c4e3ae07e25205782ac43b62ce11 to your computer and use it in GitHub Desktop.
Single Responsibility coding challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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