@@ -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 OpenAI ::Converter | Class
58+ in OpenAI ::Converter | Class | Symbol
5959 -> { spec }
6060 in true | false
6161 -> { OpenAI ::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 OpenAI ::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 OpenAI ::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 } , _ ]
@@ -367,7 +381,14 @@ class << self
367381 #
368382 # @return [Symbol, Object]
369383 #
370- def coerce ( value ) = ( value . is_a? ( String ) ? value . to_sym : value )
384+ def coerce ( value )
385+ case value
386+ in Symbol | String if values . include? ( val = value . to_sym )
387+ val
388+ else
389+ value
390+ end
391+ end
371392
372393 # @!parse
373394 # # @private
@@ -388,7 +409,7 @@ def try_strict_coerce(value)
388409 return [ true , value , 1 ] if values . include? ( value )
389410
390411 case value
391- in String if values . include? ( val = value . to_sym )
412+ in Symbol | String if values . include? ( val = value . to_sym )
392413 [ true , val , 1 ]
393414 else
394415 case [ value , values . first ]
0 commit comments