Class: Factbase::Either

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

Overview

Represents a logical “either” term. The term evaluates its operands and returns the first non-nil value.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Either

Constructor.

Parameters:

  • operands (Array)

    Operands



13
14
15
16
17
# File 'lib/factbase/terms/either.rb', line 13

def initialize(operands)
  super()
  @operands = operands
  @op = :either
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Object, Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Object)

    First operand if not nil, otherwise second operand

  • (Boolean)

    True if first operand is false OR both are true



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

def evaluate(fact, maps, fb)
  assert_args(2)
  v = _values(0, fact, maps, fb)
  return v unless v.nil?
  _values(1, fact, maps, fb)
end