Class: SyntaxTree::MLHS
Overview
MLHS represents a list of values being destructured on the left-hand side of a multiple assignment.
first, second, third = value
Instance Attribute Summary collapse
-
#comma ⇒ Object
- boolean
-
whether or not there is a trailing comma at the end of this list, which impacts destructuring.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#parts ⇒ Object
readonly
Array[ARefField | ArgStar | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
constructor
A new instance of MLHS.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
Returns a new instance of MLHS.
7242 7243 7244 7245 7246 7247 |
# File 'lib/syntax_tree/node.rb', line 7242 def initialize(parts:, comma: false, location:, comments: []) @parts = parts @comma = comma @location = location @comments = comments end |
Instance Attribute Details
#comma ⇒ Object
- boolean
-
whether or not there is a trailing comma at the end of this
list, which impacts destructuring. It’s an attr_accessor so that while the syntax tree is being built it can be set by its parent node
7234 7235 7236 |
# File 'lib/syntax_tree/node.rb', line 7234 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7240 7241 7242 |
# File 'lib/syntax_tree/node.rb', line 7240 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7237 7238 7239 |
# File 'lib/syntax_tree/node.rb', line 7237 def location @location end |
#parts ⇒ Object (readonly)
Array[ARefField | ArgStar | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment
7229 7230 7231 |
# File 'lib/syntax_tree/node.rb', line 7229 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
7249 7250 7251 |
# File 'lib/syntax_tree/node.rb', line 7249 def child_nodes parts end |
#deconstruct_keys(keys) ⇒ Object
7255 7256 7257 |
# File 'lib/syntax_tree/node.rb', line 7255 def deconstruct_keys(keys) { parts: parts, location: location, comma: comma, comments: comments } end |
#format(q) ⇒ Object
7259 7260 7261 7262 |
# File 'lib/syntax_tree/node.rb', line 7259 def format(q) q.seplist(parts) { |part| q.format(part) } q.text(",") if comma end |
#pretty_print(q) ⇒ Object
7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 |
# File 'lib/syntax_tree/node.rb', line 7264 def pretty_print(q) q.group(2, "(", ")") do q.text("mlhs") q.breakable q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
7275 7276 7277 7278 7279 7280 7281 7282 7283 |
# File 'lib/syntax_tree/node.rb', line 7275 def to_json(*opts) { type: :mlhs, parts: parts, comma: comma, loc: location, cmts: comments }.to_json(*opts) end |