Guest User

Untitled

a guest
Jan 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. # Defining the calculate method, takes 3 parameters, first, second and operator
  2. def calculate(first, second, operator)
  3. # Testing the content of Operator
  4. case operator
  5. # If the content is + we add the 2 numbers and return the result
  6. when "+" then (return "#{first} #{operator} #{second} result in #{first + second.to_f}")
  7. # If the content is - we substract the 2 numbers and return the result
  8. when "-" then (return first - second.to_f)
  9. # If the content is * we multiply the 2 numbers and return the result
  10. when "*" then (return first * second.to_f)
  11. # If the content is / we divide the 2 numbers and return the result
  12. when "/" then (return first / second.to_f)
  13. # If not an valid operation, return an error message
  14. else (return "wrong operation M8!")
  15. end # End of case
  16. end # End of method
Add Comment
Please, Sign In to add comment