Class: DSPy::Signature::StructBuilder
- Inherits:
-
Object
- Object
- DSPy::Signature::StructBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/signature.rb
Overview
DSL helper for building struct classes with field descriptions
Instance Attribute Summary collapse
-
#field_descriptors ⇒ Object
readonly
Returns the value of attribute field_descriptors.
Instance Method Summary collapse
- #build_struct_class ⇒ Object
- #const(name, type, **kwargs) ⇒ Object
-
#initialize ⇒ StructBuilder
constructor
A new instance of StructBuilder.
Constructor Details
#initialize ⇒ StructBuilder
Returns a new instance of StructBuilder.
39 40 41 |
# File 'lib/dspy/signature.rb', line 39 def initialize @field_descriptors = {} end |
Instance Attribute Details
#field_descriptors ⇒ Object (readonly)
Returns the value of attribute field_descriptors.
36 37 38 |
# File 'lib/dspy/signature.rb', line 36 def field_descriptors @field_descriptors end |
Instance Method Details
#build_struct_class ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/dspy/signature.rb', line 52 def build_struct_class descriptors = @field_descriptors Class.new(T::Struct) do extend T::Sig descriptors.each do |name, descriptor| const name, descriptor.type end end end |
#const(name, type, **kwargs) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/dspy/signature.rb', line 44 def const(name, type, **kwargs) description = kwargs[:description] has_default = kwargs.key?(:default) @field_descriptors[name] = FieldDescriptor.new(type, description, has_default) # Store default for future use if needed end |