Class: Prism::FindPatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::FindPatternNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a find pattern in pattern matching.
foo in *bar, baz, *qux
^^^^^^^^^^^^^^^
foo in [*bar, baz, *qux]
^^^^^^^^^^^^^^^^^
foo in Foo(*bar, baz, *qux)
^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#constant ⇒ Object
readonly
attr_reader constant: ConstantReadNode | ConstantPathNode | nil.
-
#left ⇒ Object
readonly
attr_reader left: SplatNode.
-
#requireds ⇒ Object
readonly
attr_reader requireds: Array.
-
#right ⇒ Object
readonly
attr_reader right: SplatNode | MissingNode.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, left: self.left, requireds: self.requireds, right: self.right, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: ConstantReadNode | ConstantPathNode | nil, ?left: SplatNode, ?requireds: Array, ?right: SplatNode | MissingNode, ?opening_loc: Location?, ?closing_loc: Location?) -> FindPatternNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc) ⇒ FindPatternNode
constructor
Initialize a new FindPatternNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String?.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location?.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc) ⇒ FindPatternNode
Initialize a new FindPatternNode node.
5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 |
# File 'lib/prism/node.rb', line 5967 def initialize(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @constant = constant @left = left @requireds = requireds @right = right @opening_loc = opening_loc @closing_loc = closing_loc end |
Instance Attribute Details
#constant ⇒ Object (readonly)
attr_reader constant: ConstantReadNode | ConstantPathNode | nil
6019 6020 6021 |
# File 'lib/prism/node.rb', line 6019 def constant @constant end |
#left ⇒ Object (readonly)
attr_reader left: SplatNode
6022 6023 6024 |
# File 'lib/prism/node.rb', line 6022 def left @left end |
#requireds ⇒ Object (readonly)
attr_reader requireds: Array
6025 6026 6027 |
# File 'lib/prism/node.rb', line 6025 def requireds @requireds end |
#right ⇒ Object (readonly)
attr_reader right: SplatNode | MissingNode
6028 6029 6030 |
# File 'lib/prism/node.rb', line 6028 def right @right end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
6077 6078 6079 |
# File 'lib/prism/node.rb', line 6077 def self.type :find_pattern_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 |
# File 'lib/prism/node.rb', line 6083 def ===(other) other.is_a?(FindPatternNode) && (constant === other.constant) && (left === other.left) && (requireds.length == other.requireds.length) && requireds.zip(other.requireds).all? { |left, right| left === right } && (right === other.right) && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
5981 5982 5983 |
# File 'lib/prism/node.rb', line 5981 def accept(visitor) visitor.visit_find_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5986 5987 5988 |
# File 'lib/prism/node.rb', line 5986 def child_nodes [constant, left, *requireds, right] end |
#closing ⇒ Object
def closing: () -> String?
6062 6063 6064 |
# File 'lib/prism/node.rb', line 6062 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 |
# File 'lib/prism/node.rb', line 6044 def closing_loc location = @closing_loc case location when nil nil when Location location else @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6001 6002 6003 |
# File 'lib/prism/node.rb', line 6001 def comment_targets [*constant, left, *requireds, right, *opening_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
5991 5992 5993 5994 5995 5996 5997 5998 |
# File 'lib/prism/node.rb', line 5991 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant if constant compact << left compact.concat(requireds) compact << right compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, left: self.left, requireds: self.requireds, right: self.right, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: ConstantReadNode | ConstantPathNode | nil, ?left: SplatNode, ?requireds: Array, ?right: SplatNode | MissingNode, ?opening_loc: Location?, ?closing_loc: Location?) -> FindPatternNode
6006 6007 6008 |
# File 'lib/prism/node.rb', line 6006 def copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, left: self.left, requireds: self.requireds, right: self.right, opening_loc: self.opening_loc, closing_loc: self.closing_loc) FindPatternNode.new(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Object
6014 6015 6016 |
# File 'lib/prism/node.rb', line 6014 def deconstruct_keys(keys) { node_id: node_id, location: location, constant: constant, left: left, requireds: requireds, right: right, opening_loc: opening_loc, closing_loc: closing_loc } end |
#inspect ⇒ Object
def inspect -> String
6067 6068 6069 |
# File 'lib/prism/node.rb', line 6067 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
6057 6058 6059 |
# File 'lib/prism/node.rb', line 6057 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 |
# File 'lib/prism/node.rb', line 6031 def opening_loc location = @opening_loc case location when nil nil when Location location else @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
6072 6073 6074 |
# File 'lib/prism/node.rb', line 6072 def type :find_pattern_node end |