Factorial in Ruby with error handling