Class: Prism::RequiredDestructuredParameterNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::RequiredDestructuredParameterNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a destructured required parameter node.
def foo((bar, baz))
^^^^^^^^^^
end
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location.
-
#parameters ⇒ Object
readonly
attr_reader parameters: Array.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> RequiredDestructuredParameterNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location].
-
#initialize(parameters, opening_loc, closing_loc, location) ⇒ RequiredDestructuredParameterNode
constructor
def initialize: (parameters: Array, opening_loc: Location, closing_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> 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(parameters, opening_loc, closing_loc, location) ⇒ RequiredDestructuredParameterNode
def initialize: (parameters: Array, opening_loc: Location, closing_loc: Location, location: Location) -> void
11923 11924 11925 11926 11927 11928 |
# File 'lib/prism/node.rb', line 11923 def initialize(parameters, opening_loc, closing_loc, location) @parameters = parameters @opening_loc = opening_loc @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
11920 11921 11922 |
# File 'lib/prism/node.rb', line 11920 def closing_loc @closing_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
11917 11918 11919 |
# File 'lib/prism/node.rb', line 11917 def opening_loc @opening_loc end |
#parameters ⇒ Object (readonly)
attr_reader parameters: Array
11914 11915 11916 |
# File 'lib/prism/node.rb', line 11914 def parameters @parameters end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
11931 11932 11933 |
# File 'lib/prism/node.rb', line 11931 def accept(visitor) visitor.visit_required_destructured_parameter_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
11936 11937 11938 |
# File 'lib/prism/node.rb', line 11936 def child_nodes [*parameters] end |
#closing ⇒ Object
def closing: () -> String
11974 11975 11976 |
# File 'lib/prism/node.rb', line 11974 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
11946 11947 11948 |
# File 'lib/prism/node.rb', line 11946 def comment_targets [*parameters, opening_loc, closing_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
11941 11942 11943 |
# File 'lib/prism/node.rb', line 11941 def compact_child_nodes [*parameters] end |
#copy(**params) ⇒ Object
def copy: (**params) -> RequiredDestructuredParameterNode
11951 11952 11953 11954 11955 11956 11957 11958 |
# File 'lib/prism/node.rb', line 11951 def copy(**params) RequiredDestructuredParameterNode.new( params.fetch(:parameters) { parameters }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location]
11964 11965 11966 |
# File 'lib/prism/node.rb', line 11964 def deconstruct_keys(keys) { parameters: parameters, opening_loc: opening_loc, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
11978 11979 11980 11981 11982 11983 11984 |
# File 'lib/prism/node.rb', line 11978 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── parameters: #{inspector.list("#{inspector.prefix}│ ", parameters)}" inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String
11969 11970 11971 |
# File 'lib/prism/node.rb', line 11969 def opening opening_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
12000 12001 12002 |
# File 'lib/prism/node.rb', line 12000 def type :required_destructured_parameter_node end |