Class: SyntaxTree::Assign
Overview
Assign represents assigning something to a variable or constant. Generally, the left side of the assignment is going to be any node that ends with the name “Field”.
variable = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#target ⇒ Object
readonly
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target to assign the result of the expression to.
-
#value ⇒ Object
readonly
- untyped
-
the expression to be assigned.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:, comments: []) ⇒ Assign
constructor
A new instance of Assign.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, value:, location:, comments: []) ⇒ Assign
Returns a new instance of Assign.
1166 1167 1168 1169 1170 1171 |
# File 'lib/syntax_tree/node.rb', line 1166 def initialize(target:, value:, location:, comments: []) @target = target @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1164 1165 1166 |
# File 'lib/syntax_tree/node.rb', line 1164 def comments @comments end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
1158 1159 1160 |
# File 'lib/syntax_tree/node.rb', line 1158 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
1161 1162 1163 |
# File 'lib/syntax_tree/node.rb', line 1161 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
1173 1174 1175 |
# File 'lib/syntax_tree/node.rb', line 1173 def accept(visitor) visitor.visit_assign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1177 1178 1179 |
# File 'lib/syntax_tree/node.rb', line 1177 def child_nodes [target, value] end |
#deconstruct_keys(_keys) ⇒ Object
1183 1184 1185 |
# File 'lib/syntax_tree/node.rb', line 1183 def deconstruct_keys(_keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 |
# File 'lib/syntax_tree/node.rb', line 1187 def format(q) q.group do q.format(target) q.text(" =") if skip_indent? q.text(" ") q.format(value) else q.indent do q.breakable q.format(value) end end end end |