Determine If A String Is Numeric In Ruby
Join the DZone community and get the full member experience.Join For Free
# Determine if a string is numeric using Float and rescue # Revised short version from http://rosettacode.org/wiki/Determine_if_a_string_is_numeric#Ruby
def numeric?(s) Float(s) != nil rescue false end
Opinions expressed by DZone contributors are their own.