Module: Factbase::Debug
- Included in:
- Term
- Defined in:
- lib/factbase/terms/debug.rb
Overview
Debug terms.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
Instance Method Details
#assert(fact, maps, fb) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/factbase/terms/debug.rb', line 23 def assert(fact, maps, fb) assert_args(2) = @operands[0] unless .is_a?(String) raise ArgumentError, "A string is expected as first argument of 'assert', but '#{}' provided" end t = @operands[1] unless t.is_a?(Factbase::Term) raise ArgumentError, "A term is expected as second argument of 'assert', but '#{t}' provided" end result = t.evaluate(fact, maps, fb) # Convert result to boolean-like evaluation # Arrays are truthy if they contain at least one truthy element truthy = if result.is_a?(Array) result.any? { |v| v && v != 0 } else result && result != 0 end raise unless truthy true end |
#traced(fact, maps, fb) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/factbase/terms/debug.rb', line 14 def traced(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 |