+ 5
in what ways can ruby loop through rescue blocks? My example fails due to return types but i need something similar.
for example: input = gets.chomp unless begin input.to_i rescue input = gets.chomp end end A solution that is also valid Crystal code is preferable but not required.
2 Answers
+ 2
+ 1
Hi Bedawang.
In response to your ask, this is my answer
=begin
input=gets.chomp
unless begin
input.to_i
rescue
input = gets.chomp
end
end
=end
input= gets.chomp
if (0..9).include?(input)==false
input=input.to_i
else
continue
end
puts input