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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:, comments: []) ⇒ MAssign
constructor
A new instance of MAssign.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, value:, location:, comments: []) ⇒ MAssign
Returns a new instance of MAssign.
6152 6153 6154 6155 6156 6157 |
# File 'lib/syntax_tree/node.rb', line 6152 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
6150 6151 6152 |
# File 'lib/syntax_tree/node.rb', line 6150 def comments @comments end |
#target ⇒ Object (readonly)
- MLHS | MLHSParen
-
the target of the multiple assignment
6144 6145 6146 |
# File 'lib/syntax_tree/node.rb', line 6144 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the value being assigned
6147 6148 6149 |
# File 'lib/syntax_tree/node.rb', line 6147 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6159 6160 6161 |
# File 'lib/syntax_tree/node.rb', line 6159 def accept(visitor) visitor.visit_massign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6163 6164 6165 |
# File 'lib/syntax_tree/node.rb', line 6163 def child_nodes [target, value] end |
#deconstruct_keys(_keys) ⇒ Object
6169 6170 6171 |
# File 'lib/syntax_tree/node.rb', line 6169 def deconstruct_keys(_keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 |
# File 'lib/syntax_tree/node.rb', line 6173 def format(q) q.group do q.group { q.format(target) } q.text(" =") q.indent do q.breakable q.format(value) end end end |