Class: Factbase::Undef

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

Overview

License

MIT

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Undef

Constructor.

Parameters:

  • operands (Array)

    Operands



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

def initialize(operands)
  super()
  @operands = operands
end

Instance Method Details

#evaluate(_fact, _maps, _fb) ⇒ Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Boolean)

    True if definition is successfully removed.



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

def evaluate(_fact, _maps, _fb)
  assert_args(1)
  fn = @operands[0]
  raise "A symbol expected as first argument of 'undef'" unless fn.is_a?(Symbol)
  if Factbase::Term.private_instance_methods(false).include?(fn)
    Factbase::Term.class_eval("undef :#{fn}", __FILE__, __LINE__ - 1) # undef :foo
  end
  true
end