I want to force user to enter only numeric value from console. Below is my piece of code that is supposed to do that.
puts \"Enter numeric value: \" result =
If you mean integer by "numeral", then:
puts "Enter numeric value: " result = gets.chomp case result when /\D/, "" puts "Invalid input" else puts "Valid input." end
It also takes care of empty strings, which would be turned into 0 by to_i, which you probably do not want.
0
to_i