Class: RubyLLM::Contract::Invariant

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/contract/contract/invariant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, block) ⇒ Invariant

Returns a new instance of Invariant.



8
9
10
11
12
# File 'lib/ruby_llm/contract/contract/invariant.rb', line 8

def initialize(description, block)
  @description = description
  @block = block
  freeze
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/ruby_llm/contract/contract/invariant.rb', line 6

def description
  @description
end

Instance Method Details

#call(parsed_output, input: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ruby_llm/contract/contract/invariant.rb', line 14

def call(parsed_output, input: nil)
  if @block.arity >= 2
    @block.call(parsed_output, input)
  else
    @block.call(parsed_output)
  end
end