Created
July 7, 2011 19:47
-
-
Save shadoi/1070375 to your computer and use it in GitHub Desktop.
Is this string a number?
This file contains 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
# Strip leading zeroes, check if input matches after conversion to integer | |
class String | |
def is_num? | |
self.to_i.to_s == self.gsub(/^0+/, '') | |
end | |
end | |
> "045".is_num? | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment