U:RDoc::AnyMethod[iI" chunk:ETI"Enumerable#chunk;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"KEnumerates over the items, chunking them together based on the return ;TI"value of the block.;To:RDoc::Markup::BlankLineo; ; [I"QConsecutive elements which return the same block value are chunked together.;T@o; ; [I"BFor example, consecutive even numbers and odd numbers can be ;TI"chunked as follows.;T@o:RDoc::Markup::Verbatim; [I"3[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5].chunk { |n| ;TI" n.even? ;TI"}.each { |even, ary| ;TI" p [even, ary] ;TI"} ;TI"#=> [false, [3, 1]] ;TI"# [true, [4]] ;TI"# [false, [1, 5, 9]] ;TI"# [true, [2, 6]] ;TI"# [false, [5, 3, 5]] ;T: @format0o; ; [I"EThis method is especially useful for sorted series of elements. ;TI"@The following example counts words for each initial letter.;T@o; ; [I"9open("/usr/share/dict/words", "r:iso-8859-1") { |f| ;TI"Q f.chunk { |line| line.ord }.each { |ch, lines| p [ch.chr, lines.length] } ;TI"} ;TI"#=> ["\n", 1] ;TI"# ["A", 1327] ;TI"# ["B", 1372] ;TI"# ["C", 1507] ;TI"# ["D", 791] ;TI" # ... ;T; 0o; ; [I"3The following key values have special meaning:;To:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"K+nil+ and +:_separator+ specifies that the elements should be dropped.;To;;0; [o; ; [I"F+:_alone+ specifies that the element should be chunked by itself.;T@o; ; [I"IAny other symbols that begin with an underscore will raise an error:;T@o; ; [I")items.chunk { |item| :_underscore } ;TI"I#=> RuntimeError: symbols beginning with an underscore are reserved ;T; 0o; ; [I"A+nil+ and +:_separator+ can be used to ignore some elements.;T@o; ; [I"RFor example, the sequence of hyphens in svn log can be eliminated as follows:;T@o; ; [I"sep = "-"*72 + "\n" ;TI"&IO.popen("svn log README") { |f| ;TI" f.chunk { |line| ;TI" line != sep || nil ;TI" }.each { |_, lines| ;TI" pp lines ;TI" } ;TI"} ;TI"U#=> ["r20018 | knu | 2008-10-29 13:20:42 +0900 (Wed, 29 Oct 2008) | 2 lines\n", ;TI"# "\n", ;TI"D# "* README, README.ja: Update the portability section.\n", ;TI"# "\n"] ;TI"U# ["r16725 | knu | 2008-05-31 23:34:23 +0900 (Sat, 31 May 2008) | 2 lines\n", ;TI"# "\n", ;TI"F# "* README, README.ja: Add a note about default C flags.\n", ;TI"# "\n"] ;TI" # ... ;T; 0o; ; [I"BParagraphs separated by empty lines can be parsed as follows:;T@o; ; [ I"+File.foreach("README").chunk { |line| ;TI" /\A\s*\z/ !~ line || nil ;TI"}.each { |_, lines| ;TI" pp lines ;TI"} ;T; 0o; ; [I"@+:_alone+ can be used to force items into their own chunk. ;TI"FFor example, you can put lines that contain a URL by themselves, ;TI"9and chunk the rest of the lines together, like this:;T@o; ; [ I"pattern = /http/ ;TI"open(filename) { |f| ;TI"O f.chunk { |line| line =~ pattern ? :_alone : true }.each { |key, lines| ;TI" pp lines ;TI" } ;TI"} ;T; 0o; ; [I"HIf no block is given, an enumerator to `chunk` is returned instead.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Eenum.chunk { |elt| ... } -> an_enumerator ;T0[I"();T@{FI"Enumerable;TcRDoc::NormalModule00