Class: SyntaxTree::MAssign
- Inherits:
-
Object
- Object
- SyntaxTree::MAssign
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#target ⇒ Object
readonly
- MLHS | MLHSParen
-
the target of the multiple assignment.
-
#value ⇒ Object
readonly
- untyped
-
the value being assigned.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:, comments: []) ⇒ MAssign
constructor
A new instance of MAssign.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, value:, location:, comments: []) ⇒ MAssign
Returns a new instance of MAssign.
8191 8192 8193 8194 8195 8196 |
# File 'lib/syntax_tree.rb', line 8191 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
8189 8190 8191 |
# File 'lib/syntax_tree.rb', line 8189 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8186 8187 8188 |
# File 'lib/syntax_tree.rb', line 8186 def location @location end |
#target ⇒ Object (readonly)
- MLHS | MLHSParen
-
the target of the multiple assignment
8180 8181 8182 |
# File 'lib/syntax_tree.rb', line 8180 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the value being assigned
8183 8184 8185 |
# File 'lib/syntax_tree.rb', line 8183 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8198 8199 8200 |
# File 'lib/syntax_tree.rb', line 8198 def child_nodes [target, value] end |
#format(q) ⇒ Object
8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 |
# File 'lib/syntax_tree.rb', line 8202 def format(q) q.group do q.group { q.format(target) } q.text(" =") q.indent do q.breakable q.format(value) end end end |
#pretty_print(q) ⇒ Object
8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 |
# File 'lib/syntax_tree.rb', line 8213 def pretty_print(q) q.group(2, "(", ")") do q.text("massign") q.breakable q.pp(target) q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8227 8228 8229 8230 8231 8232 8233 8234 8235 |
# File 'lib/syntax_tree.rb', line 8227 def to_json(*opts) { type: :massign, target: target, value: value, loc: location, cmts: comments }.to_json(*opts) end |