0

Ruby languange - Question about CASE and gets

If I run: a = 2 case a when 1 puts "One" when 2 puts "Two" when 3 puts "Three" end My output is : Two But if I run a = gets case a when 1 puts "One" when 2 puts "Two" when 3 puts "Three" end and fill out 2 as an input, my output is: No output.

30th Nov 2016, 4:04 PM
Rafael Figueroa
Rafael Figueroa - avatar
3 ответов
+ 3
In Ruby, gets will take input as a string. So you know why the above code gives no output. To convert your input to an integer, write instead x=gets.to_i
30th Nov 2016, 4:14 PM
PythonProMaybe
+ 2
Most welcome! :)
30th Nov 2016, 4:40 PM
PythonProMaybe
0
Perfect! Thanks a lot!
30th Nov 2016, 4:38 PM
Rafael Figueroa
Rafael Figueroa - avatar