Gestionnaire de fichiers - Editer - /opt/cpanel/ea-ruby24/root/usr/share/ri/system/Enumerable/slice_when-i.ri
Arrière
U:RDoc::AnyMethod[iI"slice_when:ETI"Enumerable#slice_when;TF:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [I"6Creates an enumerator for each chunked elements. ;TI"7The beginnings of chunks are defined by the block.;To:RDoc::Markup::BlankLine o; ; [ I";This method split each chunk using adjacent elements, ;TI"#_elt_before_ and _elt_after_, ;TI"!in the receiver enumerator. ;TI"IThis method split chunks between _elt_before_ and _elt_after_ where ;TI")the block returns <code>true</code>.;T@o; ; [I"IThe block is called the length of the receiver enumerator minus one.;T@o; ; [I"DThe result enumerator yields the chunked elements as an array. ;TI"/So +each+ method can be called as follows:;T@o:RDoc::Markup::Verbatim; [I"Ienum.slice_when { |elt_before, elt_after| bool }.each { |ary| ... } ;T:@format0o; ; [I"BOther methods of the Enumerator class and Enumerable module, ;TI"2such as +to_a+, +map+, etc., are also usable.;T@o; ; [I"NFor example, one-by-one increasing subsequence can be chunked as follows:;T@o;; [I"+a = [1,2,4,9,10,11,12,15,16,19,20,21] ;TI")b = a.slice_when {|i, j| i+1 != j } ;TI"Ip b.to_a #=> [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]] ;TI"@c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last}" } ;TI"6p c #=> [[1, 2], [4], "9-12", [15, 16], "19-21"] ;TI"d = c.join(",") ;TI"&p d #=> "1,2,4,9-12,15,16,19-21" ;T; 0o; ; [I"LNear elements (threshold: 6) in sorted array can be chunked as follows:;T@o;; [I"1a = [3, 11, 14, 25, 28, 29, 29, 41, 55, 57] ;TI"-p a.slice_when {|i, j| 6 < j - i }.to_a ;TI";#=> [[3], [11, 14], [25, 28, 29, 29], [41], [55, 57]] ;T; 0o; ; [I"GIncreasing (non-decreasing) subsequence can be chunked as follows:;T@o;; [I"(a = [0, 9, 2, 2, 3, 2, 7, 5, 9, 5] ;TI")p a.slice_when {|i, j| i > j }.to_a ;TI"2#=> [[0, 9], [2, 2, 3], [2, 7], [5, 9], [5]] ;T; 0o; ; [I"8Adjacent evens and odds can be chunked as follows: ;TI"0(Enumerable#chunk is another way to do it.);T@o;; [I"(a = [7, 5, 9, 2, 0, 7, 9, 4, 2, 0] ;TI"6p a.slice_when {|i, j| i.even? != j.even? }.to_a ;TI"0#=> [[7, 5, 9], [2, 0], [7, 9], [4, 2, 0]] ;T; 0o; ; [I"WParagraphs (non-empty lines with trailing empty lines) can be chunked as follows: ;TI"2(See Enumerable#chunk to ignore empty lines.);T@o;; [I"8lines = ["foo\n", "bar\n", "\n", "baz\n", "qux\n"] ;TI"Gp lines.slice_when {|l1, l2| /\A\s*\z/ =~ l1 && /\S/ =~ l2 }.to_a ;TI"8#=> [["foo\n", "bar\n", "\n"], ["baz\n", "qux\n"]] ;T; 0o; ; [I"KEnumerable#chunk_while does the same, except splitting when the block ;TI"=returns <code>false</code> instead of <code>true</code>.;T: @fileI"enum.c;T:0@omit_headings_from_table_of_contents_below0I"Fenum.slice_when {|elt_before, elt_after| bool } -> an_enumerator ;T0[ I"();T@WFI"Enumerable;TcRDoc::NormalModule00
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Génération de la page: 0 |
proxy
|
phpinfo
|
Réglages