Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Determine If A String Or Numeric Represents A Number In Ruby

DZone's Guide to

Determine If A String Or Numeric Represents A Number In Ruby

·
Free Resource
# 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
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}