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
- untyped
-
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, #pretty_print, #to_json
Constructor Details
#initialize(target:, value:, location:) ⇒ MAssign
7406 7407 7408 7409 7410 7411 |
# File 'lib/syntax_tree/node.rb', line 7406 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
7404 7405 7406 |
# File 'lib/syntax_tree/node.rb', line 7404 def comments @comments end |
#target ⇒ Object (readonly)
- MLHS | MLHSParen
-
the target of the multiple assignment
7398 7399 7400 |
# File 'lib/syntax_tree/node.rb', line 7398 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the value being assigned
7401 7402 7403 |
# File 'lib/syntax_tree/node.rb', line 7401 def value @value end |
Instance Method Details
#===(other) ⇒ Object
7450 7451 7452 |
# File 'lib/syntax_tree/node.rb', line 7450 def ===(other) other.is_a?(MAssign) && target === other.target && value === other.value end |
#accept(visitor) ⇒ Object
7413 7414 7415 |
# File 'lib/syntax_tree/node.rb', line 7413 def accept(visitor) visitor.visit_massign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7417 7418 7419 |
# File 'lib/syntax_tree/node.rb', line 7417 def child_nodes [target, value] end |
#copy(target: nil, value: nil, location: nil) ⇒ Object
7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 |
# File 'lib/syntax_tree/node.rb', line 7421 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
7435 7436 7437 |
# File 'lib/syntax_tree/node.rb', line 7435 def deconstruct_keys(_keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 |
# File 'lib/syntax_tree/node.rb', line 7439 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 |