Class: SyntaxTree::Unary
Overview
Unary represents a unary method being called on an expression, as in ! or ~.
!value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#operator ⇒ Object
readonly
- String
-
the operator being used.
-
#statement ⇒ Object
readonly
- 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(operator: nil, statement: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(operator:, statement:, location:) ⇒ Unary
constructor
A new instance of Unary.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(operator:, statement:, location:) ⇒ Unary
Returns a new instance of Unary.
11123 11124 11125 11126 11127 11128 |
# File 'lib/syntax_tree/node.rb', line 11123 def initialize(operator:, statement:, location:) @operator = operator @statement = statement @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11121 11122 11123 |
# File 'lib/syntax_tree/node.rb', line 11121 def comments @comments end |
#operator ⇒ Object (readonly)
- String
-
the operator being used
11115 11116 11117 |
# File 'lib/syntax_tree/node.rb', line 11115 def operator @operator end |
#statement ⇒ Object (readonly)
- Node
-
the statement on which to operate
11118 11119 11120 |
# File 'lib/syntax_tree/node.rb', line 11118 def statement @statement end |
Instance Method Details
#===(other) ⇒ Object
11166 11167 11168 11169 |
# File 'lib/syntax_tree/node.rb', line 11166 def ===(other) other.is_a?(Unary) && operator === other.operator && statement === other.statement end |
#accept(visitor) ⇒ Object
11130 11131 11132 |
# File 'lib/syntax_tree/node.rb', line 11130 def accept(visitor) visitor.visit_unary(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11134 11135 11136 |
# File 'lib/syntax_tree/node.rb', line 11134 def child_nodes [statement] end |
#copy(operator: nil, statement: nil, location: nil) ⇒ Object
11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 |
# File 'lib/syntax_tree/node.rb', line 11138 def copy(operator: nil, statement: nil, location: nil) node = Unary.new( operator: operator || self.operator, statement: statement || self.statement, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11152 11153 11154 11155 11156 11157 11158 11159 |
# File 'lib/syntax_tree/node.rb', line 11152 def deconstruct_keys(_keys) { operator: operator, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
11161 11162 11163 11164 |
# File 'lib/syntax_tree/node.rb', line 11161 def format(q) q.text(operator) q.format(statement) end |