Class: Prism::ArrayPatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ArrayPatternNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents an array pattern in pattern matching.
foo in 1, 2
^^^^^^^^^^^
foo in [1, 2]
^^^^^^^^^^^^^
foo in *1
^^^^^^^^^
foo in Bar[]
^^^^^^^^^^^^
foo in Bar[1, 2, 3]
^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#constant ⇒ Object
readonly
attr_reader constant: ConstantReadNode | ConstantPathNode | nil.
-
#posts ⇒ Object
readonly
attr_reader posts: Array.
-
#requireds ⇒ Object
readonly
attr_reader requireds: Array.
-
#rest ⇒ Object
readonly
attr_reader rest: Prism::node?.
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, requireds: self.requireds, rest: self.rest, posts: self.posts, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc) ⇒ ArrayPatternNode
constructor
Initialize a new ArrayPatternNode 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, requireds, rest, posts, opening_loc, closing_loc) ⇒ ArrayPatternNode
Initialize a new ArrayPatternNode node.
890 891 892 893 894 895 896 897 898 899 900 901 |
# File 'lib/prism/node.rb', line 890 def initialize(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @constant = constant @requireds = requireds @rest = rest @posts = posts @opening_loc = opening_loc @closing_loc = closing_loc end |
Instance Attribute Details
#constant ⇒ Object (readonly)
attr_reader constant: ConstantReadNode | ConstantPathNode | nil
942 943 944 |
# File 'lib/prism/node.rb', line 942 def constant @constant end |
#posts ⇒ Object (readonly)
attr_reader posts: Array
951 952 953 |
# File 'lib/prism/node.rb', line 951 def posts @posts end |
#requireds ⇒ Object (readonly)
attr_reader requireds: Array
945 946 947 |
# File 'lib/prism/node.rb', line 945 def requireds @requireds end |
#rest ⇒ Object (readonly)
attr_reader rest: Prism::node?
948 949 950 |
# File 'lib/prism/node.rb', line 948 def rest @rest end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1000 1001 1002 |
# File 'lib/prism/node.rb', line 1000 def self.type :array_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.
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/prism/node.rb', line 1006 def ===(other) other.is_a?(ArrayPatternNode) && (constant === other.constant) && (requireds.length == other.requireds.length) && requireds.zip(other.requireds).all? { |left, right| left === right } && (rest === other.rest) && (posts.length == other.posts.length) && posts.zip(other.posts).all? { |left, right| left === right } && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
904 905 906 |
# File 'lib/prism/node.rb', line 904 def accept(visitor) visitor.visit_array_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
909 910 911 |
# File 'lib/prism/node.rb', line 909 def child_nodes [constant, *requireds, rest, *posts] end |
#closing ⇒ Object
def closing: () -> String?
985 986 987 |
# File 'lib/prism/node.rb', line 985 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
967 968 969 970 971 972 973 974 975 976 977 |
# File 'lib/prism/node.rb', line 967 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]
924 925 926 |
# File 'lib/prism/node.rb', line 924 def comment_targets [*constant, *requireds, *rest, *posts, *opening_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
914 915 916 917 918 919 920 921 |
# File 'lib/prism/node.rb', line 914 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant if constant compact.concat(requireds) compact << rest if rest compact.concat(posts) compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, requireds: self.requireds, rest: self.rest, posts: self.posts, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
929 930 931 |
# File 'lib/prism/node.rb', line 929 def copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, requireds: self.requireds, rest: self.rest, posts: self.posts, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ArrayPatternNode.new(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Object
937 938 939 |
# File 'lib/prism/node.rb', line 937 def deconstruct_keys(keys) { node_id: node_id, location: location, constant: constant, requireds: requireds, rest: rest, posts: posts, opening_loc: opening_loc, closing_loc: closing_loc } end |
#inspect ⇒ Object
def inspect -> String
990 991 992 |
# File 'lib/prism/node.rb', line 990 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
980 981 982 |
# File 'lib/prism/node.rb', line 980 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
954 955 956 957 958 959 960 961 962 963 964 |
# File 'lib/prism/node.rb', line 954 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`.
995 996 997 |
# File 'lib/prism/node.rb', line 995 def type :array_pattern_node end |