Created
July 24, 2013 20:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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