@@ -55,11 +55,11 @@ def type_info(spec)
5555 type_info ( spec . slice ( :const , :enum , :union ) . first &.last )
5656 in Proc
5757 spec
58- in Orb ::Converter | Class
58+ in Orb ::Converter | Class | Symbol
5959 -> { spec }
6060 in true | false
6161 -> { Orb ::BooleanModel }
62- in NilClass | true | false | Symbol | Integer | Float
62+ in NilClass | Integer | Float
6363 -> { spec . class }
6464 end
6565 end
@@ -82,6 +82,13 @@ def coerce(target, value)
8282 case target
8383 in Orb ::Converter
8484 target . coerce ( value )
85+ in Symbol
86+ case value
87+ in Symbol | String if ( val = value . to_sym ) == target
88+ val
89+ else
90+ value
91+ end
8592 in Class
8693 case target
8794 in -> { _1 <= NilClass }
@@ -140,6 +147,13 @@ def try_strict_coerce(target, value)
140147 case target
141148 in Orb ::Converter
142149 target . try_strict_coerce ( value )
150+ in Symbol
151+ case value
152+ in Symbol | String if ( val = value . to_sym ) == target
153+ [ true , val , 1 ]
154+ else
155+ [ false , false , 0 ]
156+ end
143157 in Class
144158 case [ target , value ]
145159 in [ -> { _1 <= NilClass } , _ ]
@@ -363,7 +377,14 @@ class << self
363377 #
364378 # @return [Symbol, Object]
365379 #
366- def coerce ( value ) = ( value . is_a? ( String ) ? value . to_sym : value )
380+ def coerce ( value )
381+ case value
382+ in Symbol | String if values . include? ( val = value . to_sym )
383+ val
384+ else
385+ value
386+ end
387+ end
367388
368389 # @!parse
369390 # # @private
@@ -384,7 +405,7 @@ def try_strict_coerce(value)
384405 return [ true , value , 1 ] if values . include? ( value )
385406
386407 case value
387- in String if values . include? ( val = value . to_sym )
408+ in Symbol | String if values . include? ( val = value . to_sym )
388409 [ true , val , 1 ]
389410 else
390411 case [ value , values . first ]
0 commit comments