Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/kojo/extensions/string.rb
Instance Method Summary collapse
-
#to_typed ⇒ Object
Convert a string to the most appropriate type.
Instance Method Details
#to_typed ⇒ Object
Convert a string to the most appropriate type
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kojo/extensions/string.rb', line 3 def to_typed if self =~ /\A[+-]?\d+\Z/ self.to_i elsif self =~ /\A[+-]?\d+\.\d+\Z/ self.to_f elsif %w[yes no true false].include? downcase %w[yes true].include? downcase else self end end |