Class: Typed::Coercion::FloatCoercer
- Extended by:
- T::Generic
- Defined in:
- lib/typed/coercion/float_coercer.rb
Constant Summary collapse
- Target =
type_member { {fixed: Float} }
Instance Method Summary collapse
Instance Method Details
#coerce(type:, value:) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/typed/coercion/float_coercer.rb', line 16 def coerce(type:, value:) return Failure.new(CoercionError.new("Type must be a Float.")) unless used_for_type?(type) Success.new(Float(value)) rescue ArgumentError, TypeError Failure.new(CoercionError.new("'#{value}' cannot be coerced into Float.")) end |