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, #pretty_print, #to_json
Constructor Details
#initialize(name:, location:) ⇒ RestParam
9502
9503
9504
9505
9506
|
# File 'lib/syntax_tree/node.rb', line 9502
def initialize(name:, location:)
@name = name
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9500
9501
9502
|
# File 'lib/syntax_tree/node.rb', line 9500
def
end
|
#name ⇒ Object
- nil | Ident
-
the name of the parameter
9497
9498
9499
|
# File 'lib/syntax_tree/node.rb', line 9497
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
9538
9539
9540
|
# File 'lib/syntax_tree/node.rb', line 9538
def ===(other)
other.is_a?(RestParam) && name === other.name
end
|
#accept(visitor) ⇒ Object
9508
9509
9510
|
# File 'lib/syntax_tree/node.rb', line 9508
def accept(visitor)
visitor.visit_rest_param(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
9512
9513
9514
|
# File 'lib/syntax_tree/node.rb', line 9512
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
|
# File 'lib/syntax_tree/node.rb', line 9516
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
9529
9530
9531
|
# File 'lib/syntax_tree/node.rb', line 9529
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
9533
9534
9535
9536
|
# File 'lib/syntax_tree/node.rb', line 9533
def format(q)
q.text("*")
q.format(name) if name
end
|