Menu
CoddyTech

Recap: Safe Ratio

Lesson 25 of 48 in Coddy's Ruby for PHP Developers course.

challenge icon

Challenge

Easy

Input has exactly two tokens. Parse each using Integer(token,10). Reject malformed integers or a zero divisor with invalid; otherwise return integer floor division. Rescue only ArgumentError and ZeroDivisionError.

Return text from solve(input) without printing. The locked driver prints the returned text with one final newline and checks required public APIs independently.

Your code goes in exercise.rb. main.rb holds the supplied input/output code and cannot be edited.

Try it yourself

require_relative 'exercise'
def check(value)
  raise 'Public API check failed' unless value
end

puts solve(STDIN.read)

All lessons in Ruby for PHP Developers

Practice on your own: Online Ruby compiler