Class: Propose::Tree::UnaryOperation
- Defined in:
- lib/propose/tree/unary_operation.rb
Overview
Represents an operation on a single propositional formula.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children ⇒ Object
-
#initialize(operator, formula) ⇒ UnaryOperation
constructor
A new instance of UnaryOperation.
- #inspect ⇒ Object
- #literal? ⇒ Boolean
- #to_s ⇒ Object
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
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
4 5 6 |
# File 'lib/propose/tree/unary_operation.rb', line 4 def formula @formula end |
#operator ⇒ Object (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 |
#children ⇒ Object
15 16 17 |
# File 'lib/propose/tree/unary_operation.rb', line 15 def children [formula] end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/propose/tree/unary_operation.rb', line 23 def inspect "#<#{self.class.name.split('::').last} #{formula.inspect}>" end |
#literal? ⇒ Boolean
19 20 21 |
# File 'lib/propose/tree/unary_operation.rb', line 19 def literal? @formula.literal? end |
#to_s ⇒ Object
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 |