class SyntaxTree::Not
Not
represents the unary not
method being called on an expression.
not value
Attributes
parentheses[R]
- boolean
-
whether or not parentheses were used
parentheses?[R]
- boolean
-
whether or not parentheses were used
statement[R]
- nil |
Node
-
the statement on which to operate
Public Class Methods
new(statement:, parentheses:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 11088 def initialize(statement:, parentheses:, location:) @statement = statement @parentheses = parentheses @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 11150 def ===(other) other.is_a?(Not) && statement === other.statement && parentheses === other.parentheses end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 11095 def accept(visitor) visitor.visit_not(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 11099 def child_nodes [statement] end
Also aliased as: deconstruct
copy(statement: nil, parentheses: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 11103 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
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 11117 def deconstruct_keys(_keys) { statement: statement, parentheses: parentheses, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 11126 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