Created
August 8, 2020 02:20
-
-
Save nnzo/8b416d3f92ee53956e91d9369cfa1590 to your computer and use it in GitHub Desktop.
Ruby String class extension
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
# 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