Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2013 20:52
Show Gist options
  • Save anonymous/6074449 to your computer and use it in GitHub Desktop.
Save anonymous/6074449 to your computer and use it in GitHub Desktop.
A couple of different ways to test whether a number is a number, even if you receive it as a string.
def isInt?(number)
true if Integer(number) rescue false
end
isInt?("13")
result = true if Integer("12") rescue false # true
result = true if Integer("test") rescue false #false
result = true if Float("test") rescue false #false
result = true if Float(13.2) rescue false #true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment