Class: SyntaxTree::Not
Overview
Not represents the unary not
method being called on an expression.
not value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#parentheses ⇒ Object
(also: #parentheses?)
readonly
- boolean
-
whether or not parentheses were used.
-
#statement ⇒ Object
readonly
- nil | Node
-
the statement on which to operate.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(statement: nil, parentheses: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, parentheses:, location:) ⇒ Not
constructor
A new instance of Not.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(statement:, parentheses:, location:) ⇒ Not
Returns a new instance of Not.
11088 11089 11090 11091 11092 11093 |
# File 'lib/syntax_tree/node.rb', line 11088 def initialize(statement:, parentheses:, location:) @statement = statement @parentheses = parentheses @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11086 11087 11088 |
# File 'lib/syntax_tree/node.rb', line 11086 def comments @comments end |
#parentheses ⇒ Object (readonly) Also known as: parentheses?
- boolean
-
whether or not parentheses were used
11082 11083 11084 |
# File 'lib/syntax_tree/node.rb', line 11082 def parentheses @parentheses end |
#statement ⇒ Object (readonly)
- nil | Node
-
the statement on which to operate
11079 11080 11081 |
# File 'lib/syntax_tree/node.rb', line 11079 def statement @statement end |
Instance Method Details
#===(other) ⇒ Object
11150 11151 11152 11153 |
# File 'lib/syntax_tree/node.rb', line 11150 def ===(other) other.is_a?(Not) && statement === other.statement && parentheses === other.parentheses end |
#accept(visitor) ⇒ Object
11095 11096 11097 |
# File 'lib/syntax_tree/node.rb', line 11095 def accept(visitor) visitor.visit_not(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11099 11100 11101 |
# File 'lib/syntax_tree/node.rb', line 11099 def child_nodes [statement] end |
#copy(statement: nil, parentheses: nil, location: nil) ⇒ Object
11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 |
# 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) ⇒ Object
11117 11118 11119 11120 11121 11122 11123 11124 |
# File 'lib/syntax_tree/node.rb', line 11117 def deconstruct_keys(_keys) { statement: statement, parentheses: parentheses, location: location, comments: comments } end |
#format(q) ⇒ Object
11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 |
# 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 |