Class: SyntaxTree::RestParam
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::RestParam
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
RestParam represents defining a parameter in a method definition that accepts all remaining positional parameters.
def method(*rest) end
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(name:, location:) ⇒ RestParam
Returns a new instance of RestParam.
9598
9599
9600
9601
9602
|
# File 'lib/syntax_tree/node.rb', line 9598
def initialize(name:, location:)
@name = name
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9596
9597
9598
|
# File 'lib/syntax_tree/node.rb', line 9596
def
@comments
end
|
#name ⇒ Object
- nil | Ident
-
the name of the parameter
9593
9594
9595
|
# File 'lib/syntax_tree/node.rb', line 9593
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
9634
9635
9636
|
# File 'lib/syntax_tree/node.rb', line 9634
def ===(other)
other.is_a?(RestParam) && name === other.name
end
|
#accept(visitor) ⇒ Object
9604
9605
9606
|
# File 'lib/syntax_tree/node.rb', line 9604
def accept(visitor)
visitor.visit_rest_param(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
9608
9609
9610
|
# File 'lib/syntax_tree/node.rb', line 9608
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
|
# File 'lib/syntax_tree/node.rb', line 9612
def copy(name: nil, location: nil)
node =
RestParam.new(
name: name || self.name,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
9625
9626
9627
|
# File 'lib/syntax_tree/node.rb', line 9625
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
9629
9630
9631
9632
|
# File 'lib/syntax_tree/node.rb', line 9629
def format(q)
q.text("*")
q.format(name) if name
end
|