Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created April 15, 2019 09:54
Show Gist options
  • Save krokrob/d42bb58abbf7523eab22741476be97eb to your computer and use it in GitHub Desktop.
Save krokrob/d42bb58abbf7523eab22741476be97eb to your computer and use it in GitHub Desktop.
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