D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Prism
/
Pattern
/
Filename :
cdesc-Pattern.ri
back
Copy
U:RDoc::NormalClass[iI"Pattern:ETI"Prism::Pattern;TI"Object;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[ I"OA pattern is an object that wraps a Ruby pattern matching expression. The ;TI"Kexpression would normally be passed to an `in` clause within a `case` ;TI"Jexpression or a rightward assignment expression. For example, in the ;TI"following snippet:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim;[I"case node ;TI"[in ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]] ;TI" end ;T:@format0o; ;[I"Bthe pattern is the <tt>ConstantPathNode[...]</tt> expression.;T@o; ;[ I"PThe pattern gets compiled into an object that responds to #call by running ;TI"Lthe #compile method. This method itself will run back through Prism to ;TI"Jparse the expression into a tree, then walk the tree to generate the ;TI"Knecessary callable objects. For example, if you wanted to compile the ;TI"1expression above into a callable, you would:;T@o;;[I"|callable = Prism::Pattern.new("ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]").compile ;TI"callable.call(node) ;T;0o; ;[ I"PThe callable object returned by #compile is guaranteed to respond to #call ;TI"Lwith a single argument, which is the node to match against. It also is ;TI"Rguaranteed to respond to #===, which means it itself can be used in a `case` ;TI"expression, as in:;T@o;;[I"case node ;TI"when callable ;TI" end ;T;0o; ;[ I"KIf the query given to the initializer cannot be compiled into a valid ;TI"Pmatcher (either because of a syntax error or because it is using syntax we ;TI"Ido not yet support) then a Prism::Pattern::CompilationError will be ;TI"raised.;T: @fileI"lib/prism/pattern.rb;T:0@omit_headings_from_table_of_contents_below0; 0;0[[ I" query;TI"R;T:publicFI"lib/prism/pattern.rb;T[ [ [[I" class;T[[;[[I"new;T@>[:protected[ [:private[ [I" instance;T[[;[[I"compile;T@>[I" scan;T@>[;[ [;[[I"combine_and;T@>[I"combine_or;T@>[I"%compile_alternation_pattern_node;T@>[I"compile_array_pattern_node;T@>[I"compile_constant_name;T@>[I"compile_constant_path_node;T@>[I"compile_constant_read_node;T@>[I"compile_error;T@>[I"compile_hash_pattern_node;T@>[I"compile_nil_node;T@>[I"compile_node;T@>[I"$compile_regular_expression_node;T@>[I"compile_string_node;T@>[I"compile_symbol_node;T@>[ [U:RDoc::Context::Section[i 0o;;[ ; 0;0[@9I" Prism;TcRDoc::NormalModule