Class: Prism::KeywordRestParameterNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::KeywordRestParameterNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a keyword 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) -> KeywordRestParameterNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name, name_loc, operator_loc, location) ⇒ KeywordRestParameterNode
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) ⇒ KeywordRestParameterNode
def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void
8588 8589 8590 8591 8592 8593 |
# File 'lib/prism/node.rb', line 8588 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?
8579 8580 8581 |
# File 'lib/prism/node.rb', line 8579 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location?
8582 8583 8584 |
# File 'lib/prism/node.rb', line 8582 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
8585 8586 8587 |
# File 'lib/prism/node.rb', line 8585 def operator_loc @operator_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
8596 8597 8598 |
# File 'lib/prism/node.rb', line 8596 def accept(visitor) visitor.visit_keyword_rest_parameter_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
8601 8602 8603 |
# File 'lib/prism/node.rb', line 8601 def child_nodes [] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
8611 8612 8613 |
# File 'lib/prism/node.rb', line 8611 def comment_targets [*name_loc, operator_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
8606 8607 8608 |
# File 'lib/prism/node.rb', line 8606 def compact_child_nodes [] end |
#copy(**params) ⇒ Object
def copy: (**params) -> KeywordRestParameterNode
8616 8617 8618 8619 8620 8621 8622 8623 |
# File 'lib/prism/node.rb', line 8616 def copy(**params) KeywordRestParameterNode.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
8629 8630 8631 |
# File 'lib/prism/node.rb', line 8629 def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
8638 8639 8640 8641 8642 8643 8644 |
# File 'lib/prism/node.rb', line 8638 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
8634 8635 8636 |
# File 'lib/prism/node.rb', line 8634 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
8660 8661 8662 |
# File 'lib/prism/node.rb', line 8660 def type :keyword_rest_parameter_node end |