Class: SyntaxTree::MAssign
Overview
MAssign is a parent node of any kind of multiple assignment. This includes splitting out variables on the left like:
first, second, third = value
as well as splitting out variables on the right, as in:
value = first, second, third
Both sides support splats, as well as variables following them. There’s also destructuring behavior that you can achieve with the following:
first, = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#target ⇒ Object
readonly
- MLHS | MLHSParen
-
the target of the multiple assignment.
-
#value ⇒ Object
readonly
- Node
-
the value being 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:) ⇒ MAssign
constructor
A new instance of MAssign.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(target:, value:, location:) ⇒ MAssign
Returns a new instance of MAssign.
7500 7501 7502 7503 7504 7505 |
# File 'lib/syntax_tree/node.rb', line 7500 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
7498 7499 7500 |
# File 'lib/syntax_tree/node.rb', line 7498 def comments @comments end |
#target ⇒ Object (readonly)
- MLHS | MLHSParen
-
the target of the multiple assignment
7492 7493 7494 |
# File 'lib/syntax_tree/node.rb', line 7492 def target @target end |
#value ⇒ Object (readonly)
- Node
-
the value being assigned
7495 7496 7497 |
# File 'lib/syntax_tree/node.rb', line 7495 def value @value end |
Instance Method Details
#===(other) ⇒ Object
7544 7545 7546 |
# File 'lib/syntax_tree/node.rb', line 7544 def ===(other) other.is_a?(MAssign) && target === other.target && value === other.value end |
#accept(visitor) ⇒ Object
7507 7508 7509 |
# File 'lib/syntax_tree/node.rb', line 7507 def accept(visitor) visitor.visit_massign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7511 7512 7513 |
# File 'lib/syntax_tree/node.rb', line 7511 def child_nodes [target, value] end |
#copy(target: nil, value: nil, location: nil) ⇒ Object
7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 |
# File 'lib/syntax_tree/node.rb', line 7515 def copy(target: nil, value: nil, location: nil) node = MAssign.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
7529 7530 7531 |
# File 'lib/syntax_tree/node.rb', line 7529 def deconstruct_keys(_keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 |
# File 'lib/syntax_tree/node.rb', line 7533 def format(q) q.group do q.group { q.format(target) } q.text(" =") q.indent do q.breakable_space q.format(value) end end end |