Class: RubyLLM::Contract::Prompt::AST

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruby_llm/contract/prompt/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ AST

Returns a new instance of AST.



11
12
13
14
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 11

def initialize(nodes)
  @nodes = nodes.dup.freeze
  freeze
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



9
10
11
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 9

def nodes
  @nodes
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 28

def ==(other)
  other.is_a?(self.class) && nodes == other.nodes
end

#[](index) ⇒ Object



24
25
26
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 24

def [](index)
  @nodes[index]
end

#eachObject



16
17
18
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 16

def each(&)
  @nodes.each(&)
end

#sizeObject



20
21
22
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 20

def size
  @nodes.size
end

#to_aObject



32
33
34
# File 'lib/ruby_llm/contract/prompt/ast.rb', line 32

def to_a
  @nodes.map(&:to_h)
end