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.
9615
9616
9617
9618
9619
|
# File 'lib/syntax_tree/node.rb', line 9615
def initialize(name:, location:)
@name = name
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9613
9614
9615
|
# File 'lib/syntax_tree/node.rb', line 9613
def
@comments
end
|
#name ⇒ Object
- nil | Ident
-
the name of the parameter
9610
9611
9612
|
# File 'lib/syntax_tree/node.rb', line 9610
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
9651
9652
9653
|
# File 'lib/syntax_tree/node.rb', line 9651
def ===(other)
other.is_a?(RestParam) && name === other.name
end
|
#accept(visitor) ⇒ Object
9621
9622
9623
|
# File 'lib/syntax_tree/node.rb', line 9621
def accept(visitor)
visitor.visit_rest_param(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
9625
9626
9627
|
# File 'lib/syntax_tree/node.rb', line 9625
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
|
# File 'lib/syntax_tree/node.rb', line 9629
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
9642
9643
9644
|
# File 'lib/syntax_tree/node.rb', line 9642
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
9646
9647
9648
9649
|
# File 'lib/syntax_tree/node.rb', line 9646
def format(q)
q.text("*")
q.format(name) if name
end
|