Created
April 15, 2019 09:54
-
-
Save krokrob/d42bb58abbf7523eab22741476be97eb to your computer and use it in GitHub Desktop.
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
def calculator(number_one, number_two, operation) | |
# check which operator | |
case operation | |
when '+' | |
# compute the right operation | |
result = number_one + number_two | |
when '-' | |
result = number_one - number_two | |
when '*' | |
result = number_one * number_two | |
when '/' | |
result = number_one.fdiv(number_two) | |
end | |
return result | |
end | |
def checker_to_f(number) | |
if number =~ /\d+(\.\d+)?/ | |
number = number.to_f | |
else | |
puts "#{number} is not a number" | |
number = nil | |
end | |
return number | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment