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
9476
9477
9478
9479
9480
|
# File 'lib/syntax_tree/node.rb', line 9476
def initialize(name:, location:)
@name = name
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9474
9475
9476
|
# File 'lib/syntax_tree/node.rb', line 9474
def
end
|
#name ⇒ Object
- nil | Ident
-
the name of the parameter
9471
9472
9473
|
# File 'lib/syntax_tree/node.rb', line 9471
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
9512
9513
9514
|
# File 'lib/syntax_tree/node.rb', line 9512
def ===(other)
other.is_a?(RestParam) && name === other.name
end
|
#accept(visitor) ⇒ Object
9482
9483
9484
|
# File 'lib/syntax_tree/node.rb', line 9482
def accept(visitor)
visitor.visit_rest_param(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
9486
9487
9488
|
# File 'lib/syntax_tree/node.rb', line 9486
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
|
# File 'lib/syntax_tree/node.rb', line 9490
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
9503
9504
9505
|
# File 'lib/syntax_tree/node.rb', line 9503
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
9507
9508
9509
9510
|
# File 'lib/syntax_tree/node.rb', line 9507
def format(q)
q.text("*")
q.format(name) if name
end
|