Class: SyntaxTree::ExcessedComma
- Inherits:
-
Object
- Object
- SyntaxTree::ExcessedComma
- Defined in:
- lib/syntax_tree.rb
Overview
ExcessedComma represents a trailing comma in a list of block parameters. It changes the block parameters such that they will destructure.
[[1, 2, 3], [2, 3, 4]].each do |first, second,|
end
In the above example, an ExcessedComma node would appear in the third position of the Params node that is used to declare that block. The third position typically represents a rest-type parameter, but in this case is used to indicate that a trailing comma was used.
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.
-
#value ⇒ Object
readonly
- String
-
the comma.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ ExcessedComma
constructor
A new instance of ExcessedComma.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ ExcessedComma
Returns a new instance of ExcessedComma.
5426 5427 5428 5429 5430 |
# File 'lib/syntax_tree.rb', line 5426 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5424 5425 5426 |
# File 'lib/syntax_tree.rb', line 5424 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5421 5422 5423 |
# File 'lib/syntax_tree.rb', line 5421 def location @location end |
#value ⇒ Object (readonly)
- String
-
the comma
5418 5419 5420 |
# File 'lib/syntax_tree.rb', line 5418 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
5432 5433 5434 |
# File 'lib/syntax_tree.rb', line 5432 def child_nodes [] end |
#format(q) ⇒ Object
5436 5437 5438 |
# File 'lib/syntax_tree.rb', line 5436 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 |
# File 'lib/syntax_tree.rb', line 5440 def pretty_print(q) q.group(2, "(", ")") do q.text("excessed_comma") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5451 5452 5453 5454 5455 5456 5457 5458 |
# File 'lib/syntax_tree.rb', line 5451 def to_json(*opts) { type: :excessed_comma, value: value, loc: location, cmts: comments }.to_json(*opts) end |