@@ -55,11 +55,11 @@ def type_info(spec)
55
55
type_info ( spec . slice ( :const , :enum , :union ) . first &.last )
56
56
in Proc
57
57
spec
58
- in OpenAI ::Converter | Class
58
+ in OpenAI ::Converter | Class | Symbol
59
59
-> { spec }
60
60
in true | false
61
61
-> { OpenAI ::BooleanModel }
62
- in NilClass | true | false | Symbol | Integer | Float
62
+ in NilClass | Integer | Float
63
63
-> { spec . class }
64
64
end
65
65
end
@@ -82,6 +82,13 @@ def coerce(target, value)
82
82
case target
83
83
in OpenAI ::Converter
84
84
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
85
92
in Class
86
93
case target
87
94
in -> { _1 <= NilClass }
@@ -140,6 +147,13 @@ def try_strict_coerce(target, value)
140
147
case target
141
148
in OpenAI ::Converter
142
149
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
143
157
in Class
144
158
case [ target , value ]
145
159
in [ -> { _1 <= NilClass } , _ ]
@@ -367,7 +381,14 @@ class << self
367
381
#
368
382
# @return [Symbol, Object]
369
383
#
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
371
392
372
393
# @!parse
373
394
# # @private
@@ -388,7 +409,7 @@ def try_strict_coerce(value)
388
409
return [ true , value , 1 ] if values . include? ( value )
389
410
390
411
case value
391
- in String if values . include? ( val = value . to_sym )
412
+ in Symbol | String if values . include? ( val = value . to_sym )
392
413
[ true , val , 1 ]
393
414
else
394
415
case [ value , values . first ]
0 commit comments