Class: Factbase::Undef

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

Overview

Implements the undef term for Factbase, which removes a method from the class.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright (c) 2024-2026 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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(ArgumentError, "A symbol expected as first argument of 'undef'") unless fn.is_a?(Symbol)
  if Factbase::Term.private_method_defined?(fn, false)
    Factbase::Term.class_eval("undef :#{fn}", __FILE__, __LINE__ - 1)
  end
  true
end