Method: Emu.str_to_float
- Defined in:
- lib/emu.rb
.str_to_float ⇒ Emu::Decoder<Float>
Creates a decoder which converts a string to a float. It uses ++Float++ for the conversion.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/emu.rb', line 50 def self.str_to_float Decoder.new do |s| next Err.new("`#{s.inspect}` is not a String") unless s.is_a?(String) begin Ok.new(Float(s)) rescue TypeError, ArgumentError Err.new("`#{s.inspect}` can't be converted to a Float") end end end |