title: Accept only numeric input
body: <p>I want to force user to enter only numeric value from console. Below is my piece of code that is supposed to do that.</p>
  
  <pre><code>puts "Enter numeric value: "
  result = gets.chomp
  
  if result.to_i.is_a? Numeric
    puts "Valid input"
  else
    puts "Invalid input."
  end
  </code></pre>
  
  <p>It prints <code>Valid input</code> even if I enter a string value. And the reason is that every string has some equivalent numeric value in Ruby. Can someone help me fix the condition properly so that when user enters a non-numeric value, the script prompts <code>Invalid input.</code>?</p>