daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top