+ 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.

8th Jan 2019, 7:56 PM
Myersj281
Myersj281 - avatar
2 Answers
+ 2
Hmm, interesting question. Going to look into it. ShortCode , David Rueda Robles , Alex ?
8th Jan 2019, 8:52 PM
bedawang
bedawang - avatar
+ 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
8th Jan 2019, 9:23 PM
David Rueda đŸ‡Ș🇾
David Rueda  đŸ‡Ș🇾 - avatar