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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(target: nil, value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:) ⇒ Assign
constructor
A new instance of Assign.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, value:, location:) ⇒ Assign
Returns a new instance of Assign.
1414 1415 1416 1417 1418 1419 |
# File 'lib/syntax_tree/node.rb', line 1414 def initialize(target:, value:, location:) @target = target @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1412 1413 1414 |
# File 'lib/syntax_tree/node.rb', line 1412 def comments @comments end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
1406 1407 1408 |
# File 'lib/syntax_tree/node.rb', line 1406 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
1409 1410 1411 |
# File 'lib/syntax_tree/node.rb', line 1409 def value @value end |
Instance Method Details
#===(other) ⇒ Object
1464 1465 1466 |
# File 'lib/syntax_tree/node.rb', line 1464 def ===(other) other.is_a?(Assign) && target === other.target && value === other.value end |
#accept(visitor) ⇒ Object
1421 1422 1423 |
# File 'lib/syntax_tree/node.rb', line 1421 def accept(visitor) visitor.visit_assign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1425 1426 1427 |
# File 'lib/syntax_tree/node.rb', line 1425 def child_nodes [target, value] end |
#copy(target: nil, value: nil, location: nil) ⇒ Object
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/syntax_tree/node.rb', line 1429 def copy(target: nil, value: nil, location: nil) node = Assign.new( target: target || self.target, value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
1443 1444 1445 |
# File 'lib/syntax_tree/node.rb', line 1443 def deconstruct_keys(_keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
# File 'lib/syntax_tree/node.rb', line 1447 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_space q.format(value) end end end end |