I wanted to validate 'numericality' of a string (its not an attribute in an active-record model). I just need it to be a valid base 10, positive integer string. I am doing this:
class String
def numeric?
# Check if every character is a digit
!!self.match(/\A[0-9]+\Z/)
end
end
class String
def numeric?
# Check is there is *any* non-numeric character
!self.match(/[^0-9]/)
end
end
Which of these is a more plausible alternative? OR, is there any other better implementation?