Class: TruthTableObject
- Inherits:
-
Object
- Object
- TruthTableObject
- Defined in:
- lib/truthtable/truth_table_object.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize ⇒ TruthTableObject
constructor
A new instance of TruthTableObject.
- #next_plan ⇒ Object
Constructor Details
#initialize ⇒ TruthTableObject
Returns a new instance of TruthTableObject.
2 3 4 5 6 7 |
# File 'lib/truthtable/truth_table_object.rb', line 2 def initialize @checked = {} @plan = {} @order = [] @queue = [] end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
8 9 10 |
# File 'lib/truthtable/truth_table_object.rb', line 8 def order @order end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
8 9 10 |
# File 'lib/truthtable/truth_table_object.rb', line 8 def plan @plan end |
Instance Method Details
#[](index) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/truthtable/truth_table_object.rb', line 16 def [](index) s = "v[#{index}]" if @plan.has_key?(s) v = @plan[s] else fplan = @plan.dup fplan[s] = false fkey = fplan.keys.sort.map {|k| "#{k}=#{fplan[k]}" }.join(' ') @order += [s] @plan = fplan v = false if !@checked[fkey] tplan = @plan.dup tplan[s] = true tkey = tplan.keys.sort.map {|k| "#{k}=#{tplan[k]}" }.join(' ') torder = @order.dup torder[-1] = s @queue.unshift [tplan, torder] @checked[tkey] = true @checked[fkey] = true end end v end |
#next_plan ⇒ Object
10 11 12 13 14 |
# File 'lib/truthtable/truth_table_object.rb', line 10 def next_plan @log = {} @plan, @order = @queue.shift @plan end |