⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.116
Server IP:
78.40.11.138
Server:
Linux tango.o2switch.net 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
Server Software:
Apache
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
opt
/
alt
/
ruby19
/
share
/
ri
/
1.9.1
/
system
/
Enumerable
/
View File Name :
chunk-i.ri
U:RDoc::AnyMethod[iI" chunk:ETI"Enumerable#chunk;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"5Creates an enumerator for each chunked elements.;TI"FThe consecutive elements which have same block value are chunked.;To:RDoc::Markup::BlankLine o; ; [I"SThe result enumerator yields the block value and an array of chunked elements.;TI"/So "each" method can be called as follows.;T@o:RDoc::Markup::Verbatim; [I"4enum.chunk {|elt| key }.each {|key, ary| ... } ;FI"Jenum.chunk(initial_state) {|elt, state| key }.each {|key, ary| ... } ;Fo; ; [I"AFor example, consecutive even numbers and odd numbers can be;TI"splitted as follows.;T@o;; [I"([3,1,4,1,5,9,2,6,5,3,5].chunk {|n| ;FI" n.even? ;FI"}.each {|even, ary| ;FI" p [even, ary] ;FI"} ;FI"#=> [false, [3, 1]] ;FI"# [true, [4]] ;FI"# [false, [1, 5, 9]] ;FI"# [true, [2, 6]] ;FI"# [false, [5, 3, 5]] ;Fo; ; [I"DThis method is especially useful for sorted series of elements.;TI"@The following example counts words for each initial letter.;T@o;; [I"8open("/usr/share/dict/words", "r:iso-8859-1") {|f| ;FI"O f.chunk {|line| line.ord }.each {|ch, lines| p [ch.chr, lines.length] } ;FI"} ;FI"#=> ["\n", 1] ;FI"# ["A", 1327] ;FI"# ["B", 1372] ;FI"# ["C", 1507] ;FI"# ["D", 791] ;FI" # ... ;Fo; ; [I"2The following key values has special meaning:;To:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"Anil and :_separator specifies that the elements are dropped.;To;;0; [o; ; [I"I:_alone specifies that the element should be chunked as a singleton.;To; ; [I";Other symbols which begins an underscore are reserved.;T@o; ; [I"=nil and :_separator can be used to ignore some elements.;TI"RFor example, the sequence of hyphens in svn log can be eliminated as follows.;T@o;; [I"sep = "-"*72 + "\n" ;FI"%IO.popen("svn log README") {|f| ;FI" f.chunk {|line| ;FI" line != sep || nil ;FI" }.each {|_, lines| ;FI" pp lines ;FI" } ;FI"} ;FI"U#=> ["r20018 | knu | 2008-10-29 13:20:42 +0900 (Wed, 29 Oct 2008) | 2 lines\n", ;FI"# "\n", ;FI"D# "* README, README.ja: Update the portability section.\n", ;FI"# "\n"] ;FI"U# ["r16725 | knu | 2008-05-31 23:34:23 +0900 (Sat, 31 May 2008) | 2 lines\n", ;FI"# "\n", ;FI"F# "* README, README.ja: Add a note about default C flags.\n", ;FI"# "\n"] ;FI" # ... ;Fo; ; [I"Bparagraphs separated by empty lines can be parsed as follows.;T@o;; [ I"*File.foreach("README").chunk {|line| ;FI" /\A\s*\z/ !~ line || nil ;FI"}.each {|_, lines| ;FI" pp lines ;FI"} ;Fo; ; [I";:_alone can be used to pass through bunch of elements.;TI">For example, sort consecutive lines formed as Foo#bar and;TI"4pass other lines, chunk can be used as follows.;T@o;; [I"$pat = /\A[A-Z][A-Za-z0-9_]+\#/ ;FI"open(filename) {|f| ;FI"G f.chunk {|line| pat =~ line ? $& : :_alone }.each {|key, lines| ;FI" if key != :_alone ;FI"% print lines.sort.join('') ;FI" else ;FI" print lines.join('') ;FI" end ;FI" } ;FI"} ;Fo; ; [ I"AIf the block needs to maintain state over multiple elements,;TI"*_initial_state_ argument can be used.;TI"If non-nil value is given,;TI"Jit is duplicated for each "each" method invocation of the enumerator.;TI"UThe duplicated object is passed to 2nd argument of the block for "chunk" method.;T: @file0I"enum.chunk {|elt| ... } -> an_enumerator enum.chunk(initial_state) {|elt, state| ... } -> an_enumerator ;T0[ I"(p1 = v1);FI"enum.c;T