+ 1

Why can't "gets" work to input with integer on Ruby?

Example age = gets if age <= 12 puts age

10th Jul 2017, 12:17 PM
Ferhat Sevim
Ferhat Sevim - avatar
3 Answers
+ 2
gets is for strings only For integer, use gets.to_i
10th Jul 2017, 12:33 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
Thanks Baptiste.
10th Jul 2017, 1:11 PM
Ferhat Sevim
Ferhat Sevim - avatar
+ 1
You are welcome :)
10th Jul 2017, 4:52 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar