Class: Propose::Tree::UnaryOperation

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

Overview

Represents an operation on a single propositional formula.

Direct Known Subclasses

Negation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator, formula) ⇒ UnaryOperation

Returns a new instance of UnaryOperation.



6
7
8
9
# File 'lib/propose/tree/unary_operation.rb', line 6

def initialize(operator, formula)
  @operator = operator
  @formula = formula
end

Instance Attribute Details

#formulaObject (readonly)

Returns the value of attribute formula.



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

def formula
  @formula
end

#operatorObject (readonly)

Returns the value of attribute operator.



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

def operator
  @operator
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/propose/tree/unary_operation.rb', line 11

def ==(other)
  super || @operator == other.operator && @formula == other.formula
end

#childrenObject



15
16
17
# File 'lib/propose/tree/unary_operation.rb', line 15

def children
  [formula]
end

#inspectObject



23
24
25
# File 'lib/propose/tree/unary_operation.rb', line 23

def inspect
  "#<#{self.class.name.split('::').last} #{formula.inspect}>"
end

#literal?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/propose/tree/unary_operation.rb', line 19

def literal?
  @formula.literal?
end

#to_sObject



27
28
29
30
31
# File 'lib/propose/tree/unary_operation.rb', line 27

def to_s
  output = [operator.to_s]
  output << (formula.literal? ? formula.to_s : "(#{formula})")
  output.join
end