Determine If A String Or Numeric Represents A Number In Ruby
Join the DZone community and get the full member experience.Join For Free
# Determine if a String or Numeric represents a number # From http://www.pixellatedvisions.com/2009/06/22/string-is-a-number#comment-67
def is_numeric? self.is_a?(Numeric) or (self.is_a?(String) and !!Float(self)) rescue false end
Opinions expressed by DZone contributors are their own.