Class: SyntaxTree::KwRestParam
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::KwRestParam
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
KwRestParam represents defining a parameter in a method definition that accepts all remaining keyword parameters.
def method(**kwargs) 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:) ⇒ KwRestParam
Returns a new instance of KwRestParam.
7013
7014
7015
7016
7017
|
# File 'lib/syntax_tree/node.rb', line 7013
def initialize(name:, location:)
@name = name
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7011
7012
7013
|
# File 'lib/syntax_tree/node.rb', line 7011
def
@comments
end
|
#name ⇒ Object
- nil | Ident
-
the name of the parameter
7008
7009
7010
|
# File 'lib/syntax_tree/node.rb', line 7008
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
7049
7050
7051
|
# File 'lib/syntax_tree/node.rb', line 7049
def ===(other)
other.is_a?(KwRestParam) && name === other.name
end
|
#accept(visitor) ⇒ Object
7019
7020
7021
|
# File 'lib/syntax_tree/node.rb', line 7019
def accept(visitor)
visitor.visit_kwrest_param(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7023
7024
7025
|
# File 'lib/syntax_tree/node.rb', line 7023
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
|
# File 'lib/syntax_tree/node.rb', line 7027
def copy(name: nil, location: nil)
node =
KwRestParam.new(
name: name || self.name,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7040
7041
7042
|
# File 'lib/syntax_tree/node.rb', line 7040
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
7044
7045
7046
7047
|
# File 'lib/syntax_tree/node.rb', line 7044
def format(q)
q.text("**")
q.format(name) if name
end
|