class SyntaxTree::Not
Not
represents the unary not
method being called on an expression.
not value
Attributes
- boolean
-
whether or not parentheses were used
- boolean
-
whether or not parentheses were used
- nil |
Node
-
the statement on which to operate
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 11103 def initialize(statement:, parentheses:, location:) @statement = statement @parentheses = parentheses @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 11165 def ===(other) other.is_a?(Not) && statement === other.statement && parentheses === other.parentheses end
Source
# File lib/syntax_tree/node.rb, line 11110 def accept(visitor) visitor.visit_not(self) end
Source
# File lib/syntax_tree/node.rb, line 11114 def child_nodes [statement] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 11118 def copy(statement: nil, parentheses: nil, location: nil) node = Not.new( statement: statement || self.statement, parentheses: parentheses || self.parentheses, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 11132 def deconstruct_keys(_keys) { statement: statement, parentheses: parentheses, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 11141 def format(q) q.text("not") if parentheses q.text("(") q.format(statement) if statement q.text(")") else grandparent = q.grandparent ternary = (grandparent.is_a?(IfNode) || grandparent.is_a?(UnlessNode)) && Ternaryable.call(q, grandparent) if ternary q.if_break { q.text(" ") }.if_flat { q.text("(") } q.format(statement) if statement q.if_flat { q.text(")") } if ternary else q.text(" ") q.format(statement) if statement end end end