Skip to content

Instantly share code, notes, and snippets.

@shadoi
Created July 7, 2011 19:47
Show Gist options
  • Save shadoi/1070375 to your computer and use it in GitHub Desktop.
Save shadoi/1070375 to your computer and use it in GitHub Desktop.
Is this string a number?
# 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