Class: Propose::Tree::BinaryOperation
- Defined in:
- lib/propose/tree/binary_operation.rb
Overview
Represents two propositional formula joined by a logical connective.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children ⇒ Object
-
#initialize(operator, left, right) ⇒ BinaryOperation
constructor
A new instance of BinaryOperation.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(operator, left, right) ⇒ BinaryOperation
6 7 8 9 10 |
# File 'lib/propose/tree/binary_operation.rb', line 6 def initialize(operator, left, right) @operator = operator @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
4 5 6 |
# File 'lib/propose/tree/binary_operation.rb', line 4 def left @left end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
4 5 6 |
# File 'lib/propose/tree/binary_operation.rb', line 4 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
4 5 6 |
# File 'lib/propose/tree/binary_operation.rb', line 4 def right @right end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 15 16 |
# File 'lib/propose/tree/binary_operation.rb', line 12 def ==(other) super || @operator == other.operator && @left == other.left && @right == other.right end |
#children ⇒ Object
18 19 20 |
# File 'lib/propose/tree/binary_operation.rb', line 18 def children [left, right] end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/propose/tree/binary_operation.rb', line 22 def inspect "#<#{self.class.name.split('::').last} #{left.inspect} #{right.inspect}>" end |
#to_s ⇒ Object
26 27 28 29 30 31 |
# File 'lib/propose/tree/binary_operation.rb', line 26 def to_s output = [(left.literal? ? left.to_s : "(#{left})")] output << " #{operator} " output << (right.literal? ? right.to_s : "(#{right})") output.join end |