Skip to content

Instantly share code, notes, and snippets.

@nnzo
Created August 8, 2020 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnzo/8b416d3f92ee53956e91d9369cfa1590 to your computer and use it in GitHub Desktop.
Save nnzo/8b416d3f92ee53956e91d9369cfa1590 to your computer and use it in GitHub Desktop.
Ruby String class extension
# Add .numeric?
class String
def numeric?
return true if self =~ /\A\d+\Z/
true if Float(self) rescue false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment