Class: Prism::ArrayPatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ArrayPatternNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents an array pattern in pattern matching.
foo in 1, 2
^^^^
foo in [1, 2]
^^^^^^
foo in *bar
^^^^
foo in Bar[]
^^^^^
foo in Bar[1, 2, 3]
^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :array_pattern_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#closing ⇒ String?
:call-seq: closing -> String | nil.
-
#closing_loc ⇒ Location?
:category: Locations :call-seq: closing_loc -> Location | nil.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#constant ⇒ ConstantPathNode, ...
:call-seq: constant -> ConstantPathNode | ConstantReadNode | nil.
-
#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
:call-seq: copy(**fields) -> ArrayPatternNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc) ⇒ ArrayPatternNode
constructor
Initialize a new ArrayPatternNode node.
-
#inspect ⇒ String
: () -> String.
-
#opening ⇒ String?
:call-seq: opening -> String | nil.
-
#opening_loc ⇒ Location?
:category: Locations :call-seq: opening_loc -> Location | nil.
-
#posts ⇒ Array[Prism::node]
:call-seq: posts -> Array.
-
#requireds ⇒ Array[Prism::node]
:call-seq: requireds -> Array.
-
#rest ⇒ ImplicitRestNode, ...
:call-seq: rest -> ImplicitRestNode | SplatNode | nil.
-
#save_closing_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :array_pattern_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc) ⇒ ArrayPatternNode
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 |
# File 'lib/prism/node.rb', line 1705 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 |
Class Method Details
.type ⇒ :array_pattern_node
See Node.type.
: () -> :array_pattern_node
1810 1811 1812 |
# File 'lib/prism/node.rb', line 1810 def self.type :array_pattern_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 |
# File 'lib/prism/node.rb', line 1988 def ===(other) # :nodoc: 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
See Node.accept.
: (_Visitor visitor) -> untyped
1732 1733 1734 |
# File 'lib/prism/node.rb', line 1732 def accept(visitor) visitor.visit_array_pattern_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
1739 1740 1741 |
# File 'lib/prism/node.rb', line 1739 def child_nodes [constant, *requireds, rest, *posts] end |
#closing ⇒ String?
:call-seq:
closing -> String | nil
Slice the location of closing_loc from the source.
: () -> String?
1981 1982 1983 |
# File 'lib/prism/node.rb', line 1981 def closing closing_loc&.slice end |
#closing_loc ⇒ Location?
:category: Locations :call-seq:
closing_loc -> Location | nil
Represents the closing Location of the array pattern.
foo in [1, 2]
^
: () -> Location?
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 |
# File 'lib/prism/node.rb', line 1943 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 |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
1759 1760 1761 1762 1763 1764 1765 1766 |
# File 'lib/prism/node.rb', line 1759 def compact_child_nodes compact = [] #: Array[Prism::node] if (constant = self.constant); compact << constant; end compact.concat(requireds) if (rest = self.rest); compact << rest; end compact.concat(posts) compact end |
#constant ⇒ ConstantPathNode, ...
:call-seq:
constant -> ConstantPathNode | ConstantReadNode | nil
Represents the optional constant preceding the Array
foo in Bar[]
^^^
foo in Bar[1, 2, 3]
^^^
foo in Bar::Baz[1, 2, 3]
^^^^^^^^
: () -> (ConstantPathNode | ConstantReadNode)?
1840 1841 1842 |
# File 'lib/prism/node.rb', line 1840 def constant @constant 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) ⇒ ArrayPatternNode
:call-seq:
copy(**fields) -> ArrayPatternNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: (ConstantPathNode | ConstantReadNode)?, ?requireds: Array, ?rest: (ImplicitRestNode | SplatNode)?, ?posts: Array, ?opening_loc: Location?, ?closing_loc: Location?) -> ArrayPatternNode
1774 1775 1776 |
# File 'lib/prism/node.rb', line 1774 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
# File 'lib/prism/node.rb', line 1781 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location constant requireds rest posts opening_loc closing_loc opening closing]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :constant then deconstructed[:constant] = self.constant when :requireds then deconstructed[:requireds] = self.requireds when :rest then deconstructed[:rest] = self.rest when :posts then deconstructed[:posts] = self.posts when :opening_loc then deconstructed[:opening_loc] = self.opening_loc when :closing_loc then deconstructed[:closing_loc] = self.closing_loc when :opening then deconstructed[:opening] = self.opening when :closing then deconstructed[:closing] = self.closing end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
1747 1748 1749 1750 1751 1752 1753 1754 |
# File 'lib/prism/node.rb', line 1747 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (constant = self.constant); yield constant; end requireds.each { |node| yield node } if (rest = self.rest); yield rest; end posts.each { |node| yield node } end |
#inspect ⇒ String
: () -> String
1815 1816 1817 |
# File 'lib/prism/node.rb', line 1815 def inspect # :nodoc: InspectVisitor.compose(self) end |
#opening ⇒ String?
:call-seq:
opening -> String | nil
Slice the location of opening_loc from the source.
: () -> String?
1971 1972 1973 |
# File 'lib/prism/node.rb', line 1971 def opening opening_loc&.slice end |
#opening_loc ⇒ Location?
:category: Locations :call-seq:
opening_loc -> Location | nil
Represents the opening Location of the array pattern.
foo in [1, 2]
^
: () -> Location?
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 |
# File 'lib/prism/node.rb', line 1909 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 |
#posts ⇒ Array[Prism::node]
:call-seq:
posts -> Array[Node]
Represents the elements after the rest element of the array pattern.
foo in *bar, baz
^^^
: () -> Array
1891 1892 1893 |
# File 'lib/prism/node.rb', line 1891 def posts @posts end |
#requireds ⇒ Array[Prism::node]
:call-seq:
requireds -> Array[Node]
Represents the required elements of the array pattern.
foo in [1, 2]
^ ^
: () -> Array
1857 1858 1859 |
# File 'lib/prism/node.rb', line 1857 def requireds @requireds end |
#rest ⇒ ImplicitRestNode, ...
:call-seq:
rest -> ImplicitRestNode | SplatNode | nil
Represents the rest element of the array pattern.
foo in *bar
^^^^
: () -> (ImplicitRestNode | SplatNode)?
1874 1875 1876 |
# File 'lib/prism/node.rb', line 1874 def rest @rest end |
#save_closing_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
1960 1961 1962 |
# File 'lib/prism/node.rb', line 1960 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end |
#save_opening_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
1926 1927 1928 |
# File 'lib/prism/node.rb', line 1926 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) unless @opening_loc.nil? end |
#type ⇒ :array_pattern_node
See Node#type.
: () -> :array_pattern_node
1803 1804 1805 |
# File 'lib/prism/node.rb', line 1803 def type :array_pattern_node end |