Class: Factbase::Tuples
- Inherits:
-
Object
- Object
- Factbase::Tuples
- Defined in:
- lib/factbase/tuples.rb
Overview
Tuples.
With the help of this class, it’s possible to select a few facts from a factbase at a time, which depend on each other. For example, it’s necessary to find a fact where the name is set and then find another fact, where the salary is the salary is the same as in the first found fact. Here is how:
Factbase::Tuples.new(qt, ['(exists name)', '(eq salary, {f0.salary})']).each do |a, b|
puts a.name
puts b.salary
end
Here, the {f0.salary} is a special substitution place, which is replaced by the salary of the fact that is found by the previous query. The indexing of queries starts from zero.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#each {|Array<Fact>| ... } ⇒ Integer
Iterate them one by one.
-
#initialize(fb, queries) ⇒ Tuples
constructor
A new instance of Tuples.
Constructor Details
#initialize(fb, queries) ⇒ Tuples
Returns a new instance of Tuples.
46 47 48 49 |
# File 'lib/factbase/tuples.rb', line 46 def initialize(fb, queries) @fb = fb @queries = queries end |
Instance Method Details
#each {|Array<Fact>| ... } ⇒ Integer
Iterate them one by one.
54 55 56 57 |
# File 'lib/factbase/tuples.rb', line 54 def each(&) return to_enum(__method__) unless block_given? each_rec([], @queries, &) end |