Class: Typed::Coercion::StringCoercer
- Extended by:
- T::Generic
- Defined in:
- lib/typed/coercion/string_coercer.rb
Constant Summary collapse
- Target =
type_member { {fixed: String} }
Instance Method Summary collapse
Instance Method Details
#coerce(type:, value:) ⇒ Object
16 17 18 19 20 |
# File 'lib/typed/coercion/string_coercer.rb', line 16 def coerce(type:, value:) return Failure.new(CoercionError.new("Type must be a String.")) unless used_for_type?(type) Success.new(String(value)) end |
#used_for_type?(type) ⇒ Boolean
11 12 13 |
# File 'lib/typed/coercion/string_coercer.rb', line 11 def used_for_type?(type) type == T::Utils.coerce(String) end |