Class: Prism::RestParameterNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::RestParameterNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a rest parameter to a method, block, or lambda definition.
def a(*b)
^^
end
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
attr_reader name: Symbol?.
-
#name_loc ⇒ Object
readonly
attr_reader name_loc: Location?.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> RestParameterNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name, name_loc, operator_loc, location) ⇒ RestParameterNode
constructor
def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String.
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
Constructor Details
#initialize(name, name_loc, operator_loc, location) ⇒ RestParameterNode
def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void
12336 12337 12338 12339 12340 12341 |
# File 'lib/prism/node.rb', line 12336 def initialize(name, name_loc, operator_loc, location) @name = name @name_loc = name_loc @operator_loc = operator_loc @location = location end |
Instance Attribute Details
#name ⇒ Object (readonly)
attr_reader name: Symbol?
12327 12328 12329 |
# File 'lib/prism/node.rb', line 12327 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location?
12330 12331 12332 |
# File 'lib/prism/node.rb', line 12330 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
12333 12334 12335 |
# File 'lib/prism/node.rb', line 12333 def operator_loc @operator_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
12344 12345 12346 |
# File 'lib/prism/node.rb', line 12344 def accept(visitor) visitor.visit_rest_parameter_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
12349 12350 12351 |
# File 'lib/prism/node.rb', line 12349 def child_nodes [] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
12359 12360 12361 |
# File 'lib/prism/node.rb', line 12359 def comment_targets [*name_loc, operator_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
12354 12355 12356 |
# File 'lib/prism/node.rb', line 12354 def compact_child_nodes [] end |
#copy(**params) ⇒ Object
def copy: (**params) -> RestParameterNode
12364 12365 12366 12367 12368 12369 12370 12371 |
# File 'lib/prism/node.rb', line 12364 def copy(**params) RestParameterNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
12377 12378 12379 |
# File 'lib/prism/node.rb', line 12377 def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
12386 12387 12388 12389 12390 12391 12392 |
# File 'lib/prism/node.rb', line 12386 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── name: #{name.inspect}\n" inspector << "├── name_loc: #{inspector.location(name_loc)}\n" inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" inspector.to_str end |
#operator ⇒ Object
def operator: () -> String
12382 12383 12384 |
# File 'lib/prism/node.rb', line 12382 def operator operator_loc.slice end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
12408 12409 12410 |
# File 'lib/prism/node.rb', line 12408 def type :rest_parameter_node end |