instance method
Prism::Pattern#compile_array_pattern_node
compile_array_pattern_node(node)
lib/prism/pattern.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/pattern.rb, line 119
def compile_array_pattern_node(node)
compile_error(node) if !node.rest.nil? || node.posts.any?
constant = node.constant
compiled_constant = compile_node(constant) if constant
preprocessed = node.requireds.map { |required| compile_node(required) }
compiled_requireds = ->(other) do
deconstructed = other.deconstruct
deconstructed.length == preprocessed.length &&
preprocessed
.zip(deconstructed)
.all? { |(matcher, value)| matcher.call(value) }
end
if compiled_constant
combine_and(compiled_constant, compiled_requireds)
else
compiled_requireds
end
end
in [foo, bar, baz]
See also
#compile_alternation_pattern_node
#compile_constant_name
#compile
#compile_constant_path_node
also in
3.4 · 3.3