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.
8059 8060 8061 8062 8063 8064 |
# File 'lib/syntax_tree.rb', line 8059 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
8057 8058 8059 |
# File 'lib/syntax_tree.rb', line 8057 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8054 8055 8056 |
# File 'lib/syntax_tree.rb', line 8054 def location @location end |
#target ⇒ Object (readonly)
- MLHS | MLHSParen
-
the target of the multiple assignment
8048 8049 8050 |
# File 'lib/syntax_tree.rb', line 8048 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the value being assigned
8051 8052 8053 |
# File 'lib/syntax_tree.rb', line 8051 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8066 8067 8068 |
# File 'lib/syntax_tree.rb', line 8066 def child_nodes [target, value] end |
#format(q) ⇒ Object
8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 |
# File 'lib/syntax_tree.rb', line 8070 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
8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 |
# File 'lib/syntax_tree.rb', line 8081 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
8095 8096 8097 8098 8099 8100 8101 8102 8103 |
# File 'lib/syntax_tree.rb', line 8095 def to_json(*opts) { type: :massign, target: target, value: value, loc: location, cmts: comments }.to_json(*opts) end |