Class: LogicTools::NodeOr
- Defined in:
- lib/logic_tools/logictree.rb
Overview
Represents an OR node
Instance Attribute Summary
Attributes inherited from NodeNary
Instance Method Summary collapse
-
#dup ⇒ Object
Duplicates the node.
-
#eval ⇒ Object
Computes the value of the node.
-
#initialize(*children) ⇒ NodeOr
constructor
Creates a new OR node with
children. -
#to_s ⇒ Object
Converts to a string.
-
#to_sum_product(flattened = false) ⇒ Object
Creates a sum fo product from the tree rooted by current node.
Methods inherited from NodeNary
#==, #distribute, #each, #flatten, #flatten_deep, #getVariablesRecurse, make, #reduce, #sort, #to_sym, #uniq
Methods inherited from Node
#distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #flatten, #flatten_deep, #getVariables, #hash, #inspect, #op, #simplify, #size, #to_std_conjunctive, #to_std_disjunctive, #to_sym
Constructor Details
#initialize(*children) ⇒ NodeOr
Creates a new OR node with children.
657 658 659 |
# File 'lib/logic_tools/logictree.rb', line 657 def initialize(*children) super(:or,*children) end |
Instance Method Details
#dup ⇒ Object
Duplicates the node.
662 663 664 |
# File 'lib/logic_tools/logictree.rb', line 662 def dup # :nodoc: return NodeOr.new(@children.map(&:dup)) end |
#eval ⇒ Object
Computes the value of the node.
667 668 669 |
# File 'lib/logic_tools/logictree.rb', line 667 def eval return @children.any? {|child| child.eval() == true } end |
#to_s ⇒ Object
Converts to a string.
680 681 682 683 684 685 |
# File 'lib/logic_tools/logictree.rb', line 680 def to_s # :nodoc: return @str if @str # Convert the children to string a insert "+" between them @str = @children.join("+") return @str end |
#to_sum_product(flattened = false) ⇒ Object
Creates a sum fo product from the tree rooted by current node.
Argument +flattened+ tells if the tree is already flattend
674 675 676 677 |
# File 'lib/logic_tools/logictree.rb', line 674 def to_sum_product(flattened = false) # :nodoc: return NodeOr.new( *@children.map {|child| child.to_sum_product(flatten) } ) end |