Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/panoptimon/util/string-with-as_number.rb
Overview
from perlfaq4
Instance Method Summary collapse
Instance Method Details
#as_number ⇒ Object
1 2 3 4 5 |
# File 'lib/panoptimon/util/string-with-as_number.rb', line 1 def as_number # from perlfaq4 self =~ %r{\A[+-]?(?=\.?\d)\d*\.?\d*(?:[Ee][+-]?\d+)?\z} \ ? (self =~ %r{[\.Ee]} ? self.to_f : self.to_i) : nil end |