Class: Factbase::Traced

Inherits:
TermBase show all
Defined in:
lib/factbase/terms/traced.rb

Overview

A class representing a traced term in the factbase. This class is responsible for evaluating a term and printing its evaluation result for tracing purposes.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Traced

Constructor.

Parameters:

  • operands (Array)

    Operands



14
15
16
17
18
# File 'lib/factbase/terms/traced.rb', line 14

def initialize(operands)
  super()
  @operands = operands
  @op = 'traced'
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Object

Evaluate term on a fact.

Parameters:

Returns:

  • (Object)

    Return value of the traced term



25
26
27
28
29
30
31
32
# File 'lib/factbase/terms/traced.rb', line 25

def evaluate(fact, maps, fb)
  assert_args(1)
  t = @operands[0]
  raise "A term is expected, but '#{t}' provided" unless t.is_a?(Factbase::Term)
  r = t.evaluate(fact, maps, fb)
  puts "#{self} -> #{r}"
  r
end