Add a way for class String to determine whether it has only numbers / digits or not
Not sure if that has been suggested before. If it was and not deemed fit,
please feel free to close this issue request here.
For class String, would it be possible to find out if a given String
contains only numbers, without having to do a regex check?
x = '123'
A regex will do of course:
if x =~ /^\d+$/
I was wondering if we could have a method that does something similar,
that is also easier to read.
x = '123' x.only_numbers?
Something like that.
I do not know whether the word "only" is good or not. Perhaps ".all_numbers?"
or ".all_digits?" would be better. But the name is secondary probably, more
important would be whether such a method would make sense for class String.
I am more interested in a method that will help avoid the use of a regex here.
The method should return true if the string has only numbers, and false
Anyway, thanks for reading!