Class: Propose::Tree::BinaryOperation

Inherits:
Node
  • Object
show all
Defined in:
lib/propose/tree/binary_operation.rb

Overview

Represents two propositional formula joined by a logical connective.

Direct Known Subclasses

Conjunction, Disjunction, Implication

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#literal?

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

#leftObject (readonly)

Returns the value of attribute left.



4
5
6
# File 'lib/propose/tree/binary_operation.rb', line 4

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



4
5
6
# File 'lib/propose/tree/binary_operation.rb', line 4

def operator
  @operator
end

#rightObject (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

#childrenObject



18
19
20
# File 'lib/propose/tree/binary_operation.rb', line 18

def children
  [left, right]
end

#inspectObject



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_sObject



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