Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Defining the calculate method, takes 3 parameters, first, second and operator
- def calculate(first, second, operator)
- # Testing the content of Operator
- case operator
- # If the content is + we add the 2 numbers and return the result
- when "+" then (return "#{first} #{operator} #{second} result in #{first + second.to_f}")
- # If the content is - we substract the 2 numbers and return the result
- when "-" then (return first - second.to_f)
- # If the content is * we multiply the 2 numbers and return the result
- when "*" then (return first * second.to_f)
- # If the content is / we divide the 2 numbers and return the result
- when "/" then (return first / second.to_f)
- # If not an valid operation, return an error message
- else (return "wrong operation M8!")
- end # End of case
- end # End of method
Add Comment
Please, Sign In to add comment