ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PK#]xo#   find_all-i.rinu[U:RDoc::AnyMethod[iI" find_all:ETI"Enumerable#find_all;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"8Returns an array containing all elements of +enum+ ;TI"6for which the given +block+ returns a true value.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an Enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I":(1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9] ;TI" ;TI";[1,2,3,4,5].select { |num| num.even? } #=> [2, 4] ;T: @format0o; ; [I" See also Enumerable#reject.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Zenum.find_all { |obj| block } -> array enum.find_all -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]/zip-i.rinu[U:RDoc::AnyMethod[iI"zip:ETI"Enumerable#zip;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"ATakes one element from enum and merges corresponding ;TI"Celements from each args. This generates a sequence of ;TI"Fn-element arrays, where n is one more than the ;TI"Gcount of arguments. The length of the resulting sequence will be ;TI"Genum#size. If the size of any argument is less than ;TI"Fenum#size, nil values are supplied. If ;TI"Fa block is given, it is invoked for each output array, otherwise ;TI"$an array of arrays is returned.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"a = [ 4, 5, 6 ] ;TI"b = [ 7, 8, 9 ] ;TI" ;TI"D[1, 2, 3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] ;TI"9[1, 2].zip(a, b) #=> [[1, 4, 7], [2, 5, 8]] ;TI"Ia.zip([1, 2], [8]) #=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"ienum.zip(arg, ...) -> an_array_of_array enum.zip(arg, ...) { |arr| block } -> nil ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]?$&minmax_by-i.rinu[U:RDoc::AnyMethod[iI"minmax_by:ETI"Enumerable#minmax_by;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I";Returns a two element array containing the objects in ;TI"Penum that correspond to the minimum and maximum values respectively ;TI"from the given block.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI" ["dog", "albatross"];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"benum.minmax_by { |obj| block } -> [min, max] enum.minmax_by -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]Ytake_while-i.rinu[U:RDoc::AnyMethod[iI"take_while:ETI"Enumerable#take_while;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"LPasses elements to the block until the block returns +nil+ or +false+, ;TI"Ethen stops iterating and returns an array of all prior elements.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"a = [1, 2, 3, 4, 5, 0] ;TI",a.take_while { |i| i < 3 } #=> [1, 2];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"_enum.take_while { |arr| block } -> array enum.take_while -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]ڇzz chunk-i.rinu[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"BIf the block needs to maintain state over multiple elements, ;TI".an +initial_state+ argument can be used. ;TI""If a non-nil value is given, ;TI"Ja reference to it is passed as the 2nd argument of the block for the ;TI"G+chunk+ method, so state-changes to it persist across block calls.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.chunk { |elt| ... } -> an_enumerator enum.chunk(initial_state) { |elt, state| ... } -> an_enumerator ;T0[I"(p1 = v1);T@FI"Enumerable;TcRDoc::NormalModule00PK#] SS filter-i.rinu[U:RDoc::AnyMethod[iI" filter:ETI"Enumerable#filter;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"@Returns an array containing elements selected by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI"Sreturns an array of those elements for which the block returns a truthy value:;T@o:RDoc::Markup::Verbatim; [I"C(0..9).select {|element| element % 3 == 0 } # => [0, 3, 6, 9] ;TI"Na = {foo: 0, bar: 1, baz: 2}.select {|key, value| key.start_with?('b') } ;TI"a # => {:bar=>1, :baz=>2} ;T: @format0o; ; [I"1With no block given, returns an \Enumerator.;T@o; ; [I"Related: #reject.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I"();T@FI"Enumerable;TcRDoc::NormalModule0[@!FI" find_all;TPK#] take-i.rinu[U:RDoc::AnyMethod[iI" take:ETI"Enumerable#take;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"/Returns first n elements from enum.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"a = [1, 2, 3, 4, 5, 0] ;TI"(a.take(3) #=> [1, 2, 3];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I")enum.take(n) -> array ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]0h reduce-i.rinu[U:RDoc::AnyMethod[iI" reduce:ETI"Enumerable#reduce;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"?Combines all elements of enum by applying a binary ;TI">operation, specified by a block or a symbol that names a ;TI"method or operator.;To:RDoc::Markup::BlankLineo; ; [ I"BIf you specify a block, then for each element in enum ;TI"Mthe block is passed an accumulator value (memo) and the element. ;TI"JIf you specify a symbol instead, then each element in the collection ;TI"8will be passed to the named method of memo. ;TI"GIn either case, the result becomes the new value for memo. ;TI"HAt the end of the iteration, the final value of memo is the ;TI"!return value for the method.;T@o; ; [I"OIf you do not explicitly specify an initial value for memo, ;TI"Gthen the first element of collection is used as the initial value ;TI"of memo.;T@o:RDoc::Markup::Verbatim; [I"# Sum some numbers ;TI";(5..10).reduce(:+) #=> 45 ;TI"%# Same using a block and inject ;TI";(5..10).inject { |sum, n| sum + n } #=> 45 ;TI"# Multiply some numbers ;TI"?(5..10).reduce(1, :*) #=> 151200 ;TI"# Same using a block ;TI"?(5..10).inject(1) { |product, n| product * n } #=> 151200 ;TI"# find the longest word ;TI";longest = %w{ cat sheep bear }.inject do |memo, word| ;TI"0 memo.length > word.length ? memo : word ;TI" end ;TI"?longest #=> "sheep";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.reduce(initial, sym) -> obj enum.reduce(sym) -> obj enum.reduce(initial) { |memo, obj| block } -> obj enum.reduce { |memo, obj| block } -> obj;T0[I"(p1 = v1, p2 = v2);T@.FI"Enumerable;TcRDoc::NormalModule00PK#]#vi to_a-i.rinu[U:RDoc::AnyMethod[iI" to_a:ETI"Enumerable#to_a;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I":Returns an array containing the items in enum.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"A(1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] ;TI"J{ 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]] ;TI" ;TI"require 'prime' ;TI"7Prime.entries 10 #=> [2, 3, 5, 7];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"#enum.to_a(*args) -> array;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]  first-i.rinu[U:RDoc::AnyMethod[iI" first:ETI"Enumerable#first;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"NReturns the first element, or the first +n+ elements, of the enumerable. ;TI"RIf the enumerable is empty, the first form returns nil, and the ;TI"(second form returns an empty array.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I")%w[foo bar baz].first #=> "foo" ;TI"2%w[foo bar baz].first(2) #=> ["foo", "bar"] ;TI"9%w[foo bar baz].first(10) #=> ["foo", "bar", "baz"] ;TI"&[].first #=> nil;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Cenum.first -> obj or nil enum.first(n) -> an_array ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]ư grep-i.rinu[U:RDoc::AnyMethod[iI" grep:ETI"Enumerable#grep;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"@Returns an array of every element in enum for which ;TI"IPattern === element. If the optional block is ;TI"Fsupplied, each matching element is passed to it, and the block's ;TI"*result is stored in the output array.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"=(1..100).grep 38..44 #=> [38, 39, 40, 41, 42, 43, 44] ;TI"c = IO.constants ;TI"Bc.grep(/SEEK/) #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END] ;TI"2res = c.grep(/SEEK/) { |v| IO.const_get(v) } ;TI")res #=> [0, 1, 2];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"_enum.grep(pattern) -> array enum.grep(pattern) { |obj| block } -> array ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]e group_by-i.rinu[U:RDoc::AnyMethod[iI" group_by:ETI"Enumerable#group_by;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"MGroups the collection by result of the block. Returns a hash where the ;TI"Ekeys are the evaluated result from the block and the values are ;TI"Earrays of elements in the collection that correspond to the key.;To:RDoc::Markup::BlankLineo; ; [I"4If no block is given an enumerator is returned.;T@o:RDoc::Markup::Verbatim; [I"H(1..6).group_by { |i| i%3 } #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]};T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"\enum.group_by { |obj| block } -> a_hash enum.group_by -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]{{slice_after-i.rinu[U:RDoc::AnyMethod[iI"slice_after:ETI"Enumerable#slice_after;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"6Creates an enumerator for each chunked elements. ;TI"?The ends of chunks are defined by _pattern_ and the block.;To:RDoc::Markup::BlankLineo; ; [I"PIf _pattern_ === _elt_ returns true or the block ;TI"Hreturns true for the element, the element is end of a ;TI" chunk.;T@o; ; [I"SThe === and _block_ is called from the first element to the last ;TI"element of _enum_.;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"2enum.slice_after(pattern).each { |ary| ... } ;TI"8enum.slice_after { |elt| bool }.each { |ary| ... } ;T: @format0o; ; [I"BOther methods of the Enumerator class and Enumerable module, ;TI"*such as +map+, etc., are also usable.;T@o; ; [I"GFor example, continuation lines (lines end with backslash) can be ;TI"concatenated as follows:;T@o; ; [ I":lines = ["foo\n", "bar\\\n", "baz\n", "\n", "qux\n"] ;TI"*e = lines.slice_after(/(?#=> [["foo\n"], ["bar\\\n", "baz\n"], ["\n"], ["qux\n"]] ;TI"Np e.map {|ll| ll[0...-1].map {|l| l.sub(/\\\n\z/, "") }.join + ll.last } ;TI",#=>["foo\n", "barbaz\n", "\n", "qux\n"];T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"genum.slice_after(pattern) -> an_enumerator enum.slice_after { |elt| bool } -> an_enumerator ;T0[I" (p1);T@1FI"Enumerable;TcRDoc::NormalModule00PK#]G  sort-i.rinu[U:RDoc::AnyMethod[iI" sort:ETI"Enumerable#sort;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"BReturns an array containing the items in enum sorted, ;TI"Heither according to their own <=> method, or by using ;TI"Jthe results of the supplied block. The block should return -1, 0, or ;TI"I+1 depending on the comparison between a and b. As of ;TI"GRuby 1.8, the method Enumerable#sort_by implements a ;TI"Dbuilt-in Schwartzian Transform, useful when key computation or ;TI"comparison is expensive.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"A%w(rhea kea flea).sort #=> ["flea", "kea", "rhea"] ;TI"I(1..10).sort { |a, b| b <=> a } #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Menum.sort -> array enum.sort { |a, b| block } -> array ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#] inject-i.rinu[U:RDoc::AnyMethod[iI" inject:ETI"Enumerable#inject;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"?Combines all elements of enum by applying a binary ;TI">operation, specified by a block or a symbol that names a ;TI"method or operator.;To:RDoc::Markup::BlankLineo; ; [ I"BIf you specify a block, then for each element in enum ;TI"Mthe block is passed an accumulator value (memo) and the element. ;TI"JIf you specify a symbol instead, then each element in the collection ;TI"8will be passed to the named method of memo. ;TI"GIn either case, the result becomes the new value for memo. ;TI"HAt the end of the iteration, the final value of memo is the ;TI"!return value for the method.;T@o; ; [I"OIf you do not explicitly specify an initial value for memo, ;TI"Gthen the first element of collection is used as the initial value ;TI"of memo.;T@o:RDoc::Markup::Verbatim; [I"# Sum some numbers ;TI";(5..10).reduce(:+) #=> 45 ;TI"%# Same using a block and inject ;TI";(5..10).inject { |sum, n| sum + n } #=> 45 ;TI"# Multiply some numbers ;TI"?(5..10).reduce(1, :*) #=> 151200 ;TI"# Same using a block ;TI"?(5..10).inject(1) { |product, n| product * n } #=> 151200 ;TI"# find the longest word ;TI";longest = %w{ cat sheep bear }.inject do |memo, word| ;TI"0 memo.length > word.length ? memo : word ;TI" end ;TI"?longest #=> "sheep";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.inject(initial, sym) -> obj enum.inject(sym) -> obj enum.inject(initial) { |memo, obj| block } -> obj enum.inject { |memo, obj| block } -> obj;T0[I"(p1 = v1, p2 = v2);T@.FI"Enumerable;TcRDoc::NormalModule00PK#]+WD none%3f-i.rinu[U:RDoc::AnyMethod[iI" none?:ETI"Enumerable#none?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"JPasses each element of the collection to the given block. The method ;TI"Lreturns true if the block never returns true ;TI"Qfor all elements. If the block is not given, none? will return ;TI"Ftrue only if none of the collection members is true.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"A%w{ant bear cat}.none? { |word| word.length == 5 } #=> true ;TI"B%w{ant bear cat}.none? { |word| word.length >= 4 } #=> false ;TI"A[].none? #=> true ;TI"A[nil].none? #=> true ;TI"@[nil, false].none? #=> true;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"5enum.none? [{ |obj| block }] -> true or false ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]NE min_by-i.rinu[U:RDoc::AnyMethod[iI" min_by:ETI"Enumerable#min_by;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I">Returns the object in enum that gives the minimum ;TI" value from the given block.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI"*a.min_by { |x| x.length } #=> "dog";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Uenum.min_by { |obj| block } -> obj enum.min_by -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#] keach_with_object-i.rinu[U:RDoc::AnyMethod[iI"each_with_object:ETI" Enumerable#each_with_object;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"AIterates the given block for each element with an arbitrary ;TI":object given, and returns the initially given object.;To:RDoc::Markup::BlankLineo; ; [I"1If no block is given, returns an enumerator.;T@o:RDoc::Markup::Verbatim; [I">evens = (1..10).each_with_object([]) { |i, a| a << i*2 } ;TI"-#=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.each_with_object(obj) { |(*args), memo_obj| ... } -> obj enum.each_with_object(obj) -> an_enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]kbbcdesc-Enumerable.rinu[U:RDoc::NormalModule[iI"Enumerable:ET@0o:RDoc::Markup::Document: @parts[o;;[o:RDoc::Markup::Paragraph;[ I"HThe Enumerable mixin provides collection classes with ;TI"Fseveral traversal and searching methods, and with the ability to ;TI"Dsort. The class must provide a method each, which ;TI"5yields successive members of the collection. If ;TI"8Enumerable#max, #min, or ;TI"I#sort is used, the objects in the collection must also ;TI"Himplement a meaningful <=> operator, as these methods ;TI";rely on an ordering between members of the collection.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0o;;[; I"lib/set.rb;T; 0; 0; 0[[[[[I" class;T[[: public[[:protected[[: private[[I" instance;T[[; [7[I" all?;TI" enum.c;T[I" any?;T@.[I" chunk;T@.[I" collect;T@.[I"collect_concat;T@.[I" count;T@.[I" cycle;T@.[I" detect;T@.[I" drop;T@.[I"drop_while;T@.[I"each_cons;T@.[I"each_entry;T@.[I"each_slice;T@.[I"each_with_index;T@.[I"each_with_object;T@.[I" entries;T@.[I" find;T@.[I" find_all;T@.[I"find_index;T@.[I" first;T@.[I" flat_map;T@.[I" grep;T@.[I" group_by;T@.[I" include?;T@.[I" inject;T@.[I" lazy;TI"enumerator.c;T[I"map;T@.[I"max;T@.[I" max_by;T@.[I" member?;T@.[I"min;T@.[I" min_by;T@.[I" minmax;T@.[I"minmax_by;T@.[I" none?;T@.[I" one?;T@.[I"partition;T@.[I" reduce;T@.[I" reject;T@.[I"reverse_each;T@.[I" select;T@.[I"slice_before;T@.[I" sort;T@.[I" sort_by;T@.[I" take;T@.[I"take_while;T@.[I" to_a;T@.[I" to_h;T@.[I" to_set;FI"lib/set.rb;T[I"zip;T@.[; [[;[[[U:RDoc::Context::Section[i0o;;[; 0; 0[@I"enumerator.c;T@@cRDoc::TopLevelPK#] llinclude%3f-i.rinu[U:RDoc::AnyMethod[iI" include?:ETI"Enumerable#include?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"CReturns true if any member of enum equals ;TI":obj. Equality is tested using ==.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"7IO.constants.include? :SEEK_SET #=> true ;TI"7IO.constants.include? :SEEK_NO_FURTHER #=> false;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I",enum.include?(obj) -> true or false;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]ּ%vvfilter_map-i.rinu[U:RDoc::AnyMethod[iI"filter_map:ETI"Enumerable#filter_map;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"GReturns an array containing truthy elements returned by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI"Ireturns an array containing each truthy value returned by the block:;T@o:RDoc::Markup::Verbatim; [I"c(0..9).filter_map {|i| i * 2 if i.even? } # => [0, 4, 8, 12, 16] ;TI"^{foo: 0, bar: 1, baz: 2}.filter_map {|key, value| key if value.even? } # => [:foo, :baz] ;T: @format0o; ; [I"1When no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Cfilter_map {|element| ... } -> array filter_map -> enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]s drop-i.rinu[U:RDoc::AnyMethod[iI" drop:ETI"Enumerable#drop;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"HDrops first n elements from enum, and returns rest elements ;TI"in an array.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"a = [1, 2, 3, 4, 5, 0] ;TI"(a.drop(3) #=> [4, 5, 0];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I")enum.drop(n) -> array ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]Ja{ collect-i.rinu[U:RDoc::AnyMethod[iI" collect:ETI"Enumerable#collect;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"IReturns a new array with the results of running block once ;TI"&for every element in enum.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"3(1..4).map { |i| i*i } #=> [1, 4, 9, 16] ;TI"A(1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Xenum.collect { |obj| block } -> array enum.collect -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]4]QQ lazy-i.rinu[U:RDoc::AnyMethod[iI" lazy:ETI"Enumerable#lazy;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [ I";Returns a lazy enumerator, whose methods map/collect, ;TI"Hflat_map/collect_concat, select/find_all, reject, grep, zip, take, ;TI"Btake_while, drop, and drop_while enumerate values only on an ;TI"Cas-needed basis. However, if a block is given to zip, values ;TI" are enumerated immediately.;To:RDoc::Markup::BlankLineS:RDoc::Markup::Heading: leveli: textI" Example;T@o; ; [I"5The following program finds pythagorean triples:;T@o:RDoc::Markup::Verbatim; [I"def pythagorean_triples ;TI"/ (1..Float::INFINITY).lazy.flat_map {|z| ;TI" (1..z).flat_map {|x| ;TI" (x..z).select {|y| ;TI"! x**2 + y**2 == z**2 ;TI" }.map {|y| ;TI" [x, y, z] ;TI" } ;TI" } ;TI" } ;TI" end ;TI"*# show first ten pythagorean triples ;TI"Mp pythagorean_triples.take(10).force # take is lazy, so force is needed ;TI";p pythagorean_triples.first(10) # first is eager ;TI".# show pythagorean triples less than 100 ;TI">p pythagorean_triples.take_while { |*, z| z < 100 }.force;T: @format0: @fileI"enumerator.c;T:0@omit_headings_from_table_of_contents_below0I"e.lazy -> lazy_enumerator ;T0[I"();T@*FI"Enumerable;TcRDoc::NormalModule00PK#]#M tally-i.rinu[U:RDoc::AnyMethod[iI" tally:ETI"Enumerable#tally;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I" {"a"=>2, "b"=>3, "c"=>3} ;T: @format0o; ; [I"TWith a hash argument, that hash is used for the tally (instead of a new hash), ;TI"and is returned; ;TI"Mthis may be useful for accumulating tallies across multiple enumerables:;T@o;; [ I"hash = {} ;TI"(hash = %w[a c d b c a].tally(hash) ;TI"0hash # => {"a"=>2, "c"=>2, "d"=>1, "b"=>1} ;TI""hash = %w[b a z].tally(hash) ;TI"8hash # => {"a"=>3, "c"=>2, "d"=>1, "b"=>2, "z"=>1} ;TI""hash = %w[b a m].tally(hash) ;TI"@hash # => {"a"=>4, "c"=>2, "d"=>1, "b"=>3, "z"=>1, "m"=> 1};T;0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"+tally -> new_hash tally(hash) -> hash ;T0[I" (*args);T@/FI"Enumerable;TcRDoc::NormalModule00PK#]mreverse_each-i.rinu[U:RDoc::AnyMethod[iI"reverse_each:ETI"Enumerable#reverse_each;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"HBuilds a temporary array and traverses that array in reverse order.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [ I"' (1..3).reverse_each { |v| p v } ;TI" ;TI"produces: ;TI" ;TI" 3 ;TI" 2 ;TI" 1;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"tenum.reverse_each(*args) { |item| block } -> enum enum.reverse_each(*args) -> an_enumerator ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]Ow one%3f-i.rinu[U:RDoc::AnyMethod[iI" one?:ETI"Enumerable#one?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"JPasses each element of the collection to the given block. The method ;TI"Freturns true if the block returns true ;TI"Lexactly once. If the block is not given, one? will return ;TI"Htrue only if exactly one of the collection members is ;TI" true.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"A%w{ant bear cat}.one? { |word| word.length == 4 } #=> true ;TI"B%w{ant bear cat}.one? { |word| word.length > 4 } #=> false ;TI"B%w{ant bear cat}.one? { |word| word.length < 4 } #=> false ;TI"B[ nil, true, 99 ].one? #=> false ;TI"@[ nil, true, false ].one? #=> true;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"4enum.one? [{ |obj| block }] -> true or false ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]'max-i.rinu[U:RDoc::AnyMethod[iI"max:ETI"Enumerable#max;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I">Returns the object in _enum_ with the maximum value. The ;TI"Gfirst form assumes all objects implement Comparable; ;TI":the second uses the block to return a <=> b.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI"9a.max #=> "horse" ;TI" b.length } #=> "albatross";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Genum.max -> obj enum.max { |a, b| block } -> obj ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]ȯ^!!collect_concat-i.rinu[U:RDoc::AnyMethod[iI"collect_concat:ETI"Enumerable#collect_concat;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"BReturns a new array with the concatenated results of running ;TI":block once for every element in enum.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"L[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] ;TI"K[[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"fenum.collect_concat { |obj| block } -> array enum.collect_concat -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]B select-i.rinu[U:RDoc::AnyMethod[iI" select:ETI"Enumerable#select;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"8Returns an array containing all elements of +enum+ ;TI"6for which the given +block+ returns a true value.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an Enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I":(1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9] ;TI" ;TI";[1,2,3,4,5].select { |num| num.even? } #=> [2, 4] ;T: @format0o; ; [I" See also Enumerable#reject.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Zenum.select { |obj| block } -> array enum.select -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]HDeach_cons-i.rinu[U:RDoc::AnyMethod[iI"each_cons:ETI"Enumerable#each_cons;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"@Iterates the given block for each array of consecutive ;TI" nil enum.each_cons(n) -> an_enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]Jsum-i.rinu[U:RDoc::AnyMethod[iI"sum:ETI"Enumerable#sum;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"With no block given, ;TI"9returns the sum of +initial_value+ and the elements:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"%(1..100).sum # => 5050 ;TI"%(1..100).sum(1) # => 5051 ;TI"*('a'..'d').sum('foo') # => "fooabcd" ;T: @format0o; ; [I"IGenerally, the sum is computed using methods + and +each+; ;TI"Cfor performance optimizations, those methods may not be used, ;TI"Gand so any redefinition of those methods may not have effect here.;T@o; ; [I"LOne such optimization: When possible, computes using Gauss's summation ;TI"formula n(n+1)/2:;T@o; ; [I"#100 * (100 + 1) / 2 # => 5050 ;T; 0o; ; [I" 30 ;TI";(1..4).sum(100) {|i| i*i } # => 130 ;TI".h = {a: 0, b: 1, c: 2, d: 3, e: 4, f: 5} ;TI"9h.sum {|key, value| value.odd? ? value : 0 } # => 9 ;TI"=('a'..'f').sum('x') {|c| c < 'd' ? c : '' } # => "xabc";T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"isum(initial_value = 0) -> number sum(initial_value = 0) {|element| ... } -> object ;T0[I" (*args);T@,FI"Enumerable;TcRDoc::NormalModule00PK#]4;; count-i.rinu[U:RDoc::AnyMethod[iI" count:ETI"Enumerable#count;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"@Returns the number of items in +enum+ through enumeration. ;TI"AIf an argument is given, the number of items in +enum+ that ;TI"?are equal to +item+ are counted. If a block is given, it ;TI"9counts the number of elements yielding a true value.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"ary = [1, 2, 4, 2] ;TI"#ary.count #=> 4 ;TI"#ary.count(2) #=> 2 ;TI""ary.count{ |x| x%2==0 } #=> 3;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"kenum.count -> int enum.count(item) -> int enum.count { |obj| block } -> int ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]lL all%3f-i.rinu[U:RDoc::AnyMethod[iI" all?:ETI"Enumerable#all?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"JPasses each element of the collection to the given block. The method ;TI":returns true if the block never returns ;TI"Hfalse or nil. If the block is not given, ;TI"JRuby adds an implicit block of { |obj| obj } which will ;TI"Jcause #all? to return +true+ when none of the collection members are ;TI"+false+ or +nil+.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"@%w[ant bear cat].all? { |word| word.length >= 3 } #=> true ;TI"A%w[ant bear cat].all? { |word| word.length >= 4 } #=> false ;TI"@[nil, true, 99].all? #=> false;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"5enum.all? [{ |obj| block } ] -> true or false ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]f chunk_while-i.rinu[U:RDoc::AnyMethod[iI"chunk_while:ETI"Enumerable#chunk_while;TF: privateo: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::BlankLineo; ; [ I"false.;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"Jenum.chunk_while { |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.chunk_while {|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"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.chunk_while {|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"7p a.chunk_while {|i, j| i.even? == j.even? }.to_a ;TI"0#=> [[7, 5, 9], [2, 0], [7, 9], [4, 2, 0]] ;T; 0o; ; [I"JEnumerable#slice_when does the same, except splitting when the block ;TI"=returns true instead of false.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Genum.chunk_while {|elt_before, elt_after| bool } -> an_enumerator ;T0[I"();T@FFI"Enumerable;TcRDoc::NormalModule00PK#] uniq-i.rinu[U:RDoc::AnyMethod[iI" uniq:ETI"Enumerable#uniq;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"IWith no block, returns a new array containing only unique elements; ;TI"Pthe array has no two elements +e0+ and +e1+ such that e0.eql?(e1):;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I";%w[a b c c b a a b c].uniq # => ["a", "b", "c"] ;TI"5[0, 1, 2, 2, 1, 0, 0, 1, 2].uniq # => [0, 1, 2] ;T: @format0o; ; [I"KWith a block, returns a new array containing only for which the block ;TI"returns a unique value:;T@o; ; [ I"+a = [0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1] ;TI"2a.uniq {|i| i.even? ? i : 0 } # => [0, 2, 4] ;TI"+a = %w[a b c d e e d c b a a b c d e] ;TI"2a.uniq {|c| c < 'c' } # => ["a", "c"];T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Cuniq -> array uniq {|element| ... } -> array ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]uMmin-i.rinu[U:RDoc::AnyMethod[iI"min:ETI"Enumerable#min;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"CReturns the object in enum with the minimum value. The ;TI"Gfirst form assumes all objects implement Comparable; ;TI":the second uses the block to return a <=> b.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI"=a.min #=> "albatross" ;TI"6a.min { |a, b| a.length <=> b.length } #=> "dog";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Fenum.min -> obj enum.min { |a, b| block } -> obj ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]VZ flat_map-i.rinu[U:RDoc::AnyMethod[iI" flat_map:ETI"Enumerable#flat_map;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"BReturns a new array with the concatenated results of running ;TI":block once for every element in enum.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"L[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] ;TI"K[[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"fenum.flat_map { |obj| block } -> array enum.flat_map -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]4Ofind_index-i.rinu[U:RDoc::AnyMethod[iI"find_index:ETI"Enumerable#find_index;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [ I"FCompares each entry in enum with value or passes ;TI"Gto block. Returns the index for the first for which the ;TI"Bevaluated value is non-false. If no object matches, returns ;TI"nil;To:RDoc::Markup::BlankLineo; ; [I"OIf neither block nor argument is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"D(1..10).find_index { |i| i % 5 == 0 and i % 7 == 0 } #=> nil ;TI"C(1..100).find_index { |i| i % 5 == 0 and i % 7 == 0 } #=> 34 ;TI"B(1..100).find_index(50) #=> 49;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.find_index(value) -> int or nil enum.find_index { |obj| block } -> int or nil enum.find_index -> an_enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#](ӵdrop_while-i.rinu[U:RDoc::AnyMethod[iI"drop_while:ETI"Enumerable#drop_while;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"DDrops elements up to, but not including, the first element for ;TI"Cwhich the block returns +nil+ or +false+ and returns an array ;TI"'containing the remaining elements.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"a = [1, 2, 3, 4, 5, 0] ;TI"2a.drop_while { |i| i < 3 } #=> [3, 4, 5, 0];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"aenum.drop_while { |arr| block } -> array enum.drop_while -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]Flmap-i.rinu[U:RDoc::AnyMethod[iI"map:ETI"Enumerable#map;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"IReturns a new array with the results of running block once ;TI"&for every element in enum.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"3(1..4).map { |i| i*i } #=> [1, 4, 9, 16] ;TI"A(1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Xenum.map { |obj| block } -> array enum.map -> an_enumerator;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#] compact-i.rinu[U:RDoc::AnyMethod[iI" compact:ETI"Enumerable#compact;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"0Returns an array of all non-+nil+ elements:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Fa = [nil, 0, nil, 'a', false, nil, false, nil, 'a', nil, 0, nil] ;TI"2a.compact # => [0, "a", false, false, "a", 0];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"compact -> array ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#];each_slice-i.rinu[U:RDoc::AnyMethod[iI"each_slice:ETI"Enumerable#each_slice;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"EIterates the given block for each slice of elements. If no ;TI"+block is given, returns an enumerator.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"'(1..10).each_slice(3) { |a| p a } ;TI"# outputs below ;TI"[1, 2, 3] ;TI"[4, 5, 6] ;TI"[7, 8, 9] ;TI" [10];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Wenum.each_slice(n) { ... } -> nil enum.each_slice(n) -> an_enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#] reject-i.rinu[U:RDoc::AnyMethod[iI" reject:ETI"Enumerable#reject;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"EReturns an array for all elements of +enum+ for which the given ;TI"+block+ returns false.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an Enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"E(1..10).reject { |i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10] ;TI" ;TI">[1, 2, 3, 4, 5].reject { |num| num.even? } #=> [1, 3, 5] ;T: @format0o; ; [I""See also Enumerable#find_all.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Wenum.reject { |obj| block } -> array enum.reject -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]>Gjjmember%3f-i.rinu[U:RDoc::AnyMethod[iI" member?:ETI"Enumerable#member?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"CReturns true if any member of enum equals ;TI":obj. Equality is tested using ==.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"7IO.constants.include? :SEEK_SET #=> true ;TI"7IO.constants.include? :SEEK_NO_FURTHER #=> false;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I",enum.member?(obj) -> true or false;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]z_ detect-i.rinu[U:RDoc::AnyMethod[iI" detect:ETI"Enumerable#detect;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [ I"EPasses each entry in enum to block. Returns the ;TI"9first for which block is not false. If no ;TI"Hobject matches, calls ifnone and returns its result when it ;TI"9is specified, or returns nil otherwise.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"B(1..10).detect { |i| i % 5 == 0 and i % 7 == 0 } #=> nil ;TI"@(1..100).find { |i| i % 5 == 0 and i % 7 == 0 } #=> 35;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"wenum.detect(ifnone = nil) { |obj| block } -> obj or nil enum.detect(ifnone = nil) -> an_enumerator;T0[I"(p1 = v1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]0each_entry-i.rinu[U:RDoc::AnyMethod[iI"each_entry:ETI"Enumerable#each_entry;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"FCalls block once for each element in +self+, passing that ;TI"Ielement as a parameter, converting multiple values from yield to an ;TI" array.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"class Foo ;TI" include Enumerable ;TI" def each ;TI" yield 1 ;TI" yield 1, 2 ;TI" yield ;TI" end ;TI" end ;TI"#Foo.new.each_entry{ |o| p o } ;T: @format0o; ; [I"produces:;T@o; ; [I"1 ;TI" [1, 2] ;TI"nil;T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"`enum.each_entry { |obj| block } -> enum enum.each_entry -> an_enumerator ;T0[I" (*args);T@'FI"Enumerable;TcRDoc::NormalModule00PK#]]ۘ to_set-i.rinu[U:RDoc::AnyMethod[iI" to_set:EFI"Enumerable#to_set;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"BMakes a set from the enumerable object with given arguments. ;TI"1Needs to +require "set"+ to use this method.;T: @fileI"lib/set.rb;T:0@omit_headings_from_table_of_contents_below000[I"!(klass = Set, *args, &block);T@FI"Enumerable;TcRDoc::NormalModule00PK#][qqeach_with_index-i.rinu[U:RDoc::AnyMethod[iI"each_with_index:ETI"Enumerable#each_with_index;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"FCalls block with two arguments, the item and its index, ;TI"Gfor each item in enum. Given arguments are passed through ;TI"to #each().;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [ I"hash = Hash.new ;TI"8%w(cat dog wombat).each_with_index { |item, index| ;TI" hash[item] = index ;TI"} ;TI"1hash #=> {"cat"=>0, "dog"=>1, "wombat"=>2};T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"~enum.each_with_index(*args) { |obj, i| block } -> enum enum.each_with_index(*args) -> an_enumerator ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]#!! to_h-i.rinu[U:RDoc::AnyMethod[iI" to_h:ETI"Enumerable#to_h;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"AReturns the result of interpreting enum as a list of ;TI"![key, value] pairs.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"*%i[hello world].each_with_index.to_h ;TI"& # => {:hello => 0, :world => 1};T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.to_h(*args) -> hash ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]0<< cycle-i.rinu[U:RDoc::AnyMethod[iI" cycle:ETI"Enumerable#cycle;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [ I"GCalls block for each element of enum repeatedly _n_ ;TI"Dtimes or forever if none or +nil+ is given. If a non-positive ;TI"Hnumber is given or the collection is empty, does nothing. Returns ;TI"@+nil+ if the loop has finished without getting interrupted.;To:RDoc::Markup::BlankLineo; ; [I"EEnumerable#cycle saves elements in an internal array so changes ;TI"8to enum after the first pass have no effect.;T@o; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"a = ["a", "b", "c"] ;TI"Ca.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. ;TI":a.cycle(2) { |x| puts x } # print, a, b, c, a, b, c.;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"eenum.cycle(n=nil) { |obj| block } -> nil enum.cycle(n=nil) -> an_enumerator ;T0[I"(p1 = v1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]᯲w find-i.rinu[U:RDoc::AnyMethod[iI" find:ETI"Enumerable#find;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [ I"EPasses each entry in enum to block. Returns the ;TI"9first for which block is not false. If no ;TI"Hobject matches, calls ifnone and returns its result when it ;TI"9is specified, or returns nil otherwise.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"B(1..10).detect { |i| i % 5 == 0 and i % 7 == 0 } #=> nil ;TI"@(1..100).find { |i| i % 5 == 0 and i % 7 == 0 } #=> 35;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"wenum.find(ifnone = nil) { |obj| block } -> obj or nil enum.find(ifnone = nil) -> an_enumerator;T0[I"(p1 = v1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]KQQ minmax-i.rinu[U:RDoc::AnyMethod[iI" minmax:ETI"Enumerable#minmax;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"CReturns two elements array which contains the minimum and the ;TI"Bmaximum value in the enumerable. The first form assumes all ;TI"Dobjects implement Comparable; the second uses the ;TI"&block to return a <=> b.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI"Ja.minmax #=> ["albatross", "horse"] ;TI"Ga.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"[enum.minmax -> [min, max] enum.minmax { |a, b| block } -> [min, max] ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]b b slice_when-i.rinu[U:RDoc::AnyMethod[iI"slice_when:ETI"Enumerable#slice_when;TF: privateo: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::BlankLineo; ; [ I"true.;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 false instead of true.;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::NormalModule00PK#] _ entries-i.rinu[U:RDoc::AnyMethod[iI" entries:ETI"Enumerable#entries;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I":Returns an array containing the items in enum.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"A(1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] ;TI"J{ 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]] ;TI" ;TI"require 'prime' ;TI"7Prime.entries 10 #=> [2, 3, 5, 7];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"#enum.entries(*args) -> array;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]Yl chain-i.rinu[U:RDoc::AnyMethod[iI" chain:ETI"Enumerable#chain;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"EReturns an enumerator object generated from this enumerator and ;TI"given enumerables.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"e = (1..3).chain([4, 5]) ;TI"e.to_a #=> [1, 2, 3, 4, 5];T: @format0: @fileI"enumerator.c;T:0@omit_headings_from_table_of_contents_below0I"#e.chain(*enums) -> enumerator ;T0[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00PK#]4c max_by-i.rinu[U:RDoc::AnyMethod[iI" max_by:ETI"Enumerable#max_by;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I">Returns the object in enum that gives the maximum ;TI" value from the given block.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"!a = %w(albatross dog horse) ;TI"0a.max_by { |x| x.length } #=> "albatross";T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Uenum.max_by { |obj| block } -> obj enum.max_by -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]Z grep_v-i.rinu[U:RDoc::AnyMethod[iI" grep_v:ETI"Enumerable#grep_v;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"=Returns an array of objects based on elements of +self+ ;TI"1that don't match the given pattern.;To:RDoc::Markup::BlankLineo; ; [I"CWith no block given, returns an array containing each element ;TI"7for which pattern === element is +false+:;T@o:RDoc::Markup::Verbatim; [ I"&a = ['foo', 'bar', 'car', 'moo'] ;TI":a.grep_v(/ar/) # => ["foo", "moo"] ;TI"9(1..10).grep_v(3..8) # => [1, 2, 9, 10] ;TI"6['a', 'b', 0, 1].grep_v(Integer) # => ["a", "b"] ;T: @format0o; ; [I"With a block given, ;TI"Ycalls the block with each non-matching element and returns an array containing each ;TI""object returned by the block:;T@o; ; [I"&a = ['foo', 'bar', 'car', 'moo'] ;TI"Da.grep_v(/ar/) {|element| element.upcase } # => ["FOO", "MOO"] ;T; 0o; ; [I"Related: #grep.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Hgrep_v(pattern) -> array grep_v(pattern) {|element| ... } -> array ;T0[I" (p1);T@&FI"Enumerable;TcRDoc::NormalModule00PK#]v  sort_by-i.rinu[U:RDoc::AnyMethod[iI" sort_by:ETI"Enumerable#sort_by;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"DSorts enum using a set of keys generated by mapping the ;TI"3values in enum through the given block.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"6%w{apple pear fig}.sort_by { |word| word.length} ;TI"0 #=> ["fig", "pear", "apple"] ;T: @format0o; ; [ I"EThe current implementation of sort_by generates an ;TI"Harray of tuples containing the original collection element and the ;TI"Imapped value. This makes sort_by fairly expensive when ;TI"the keysets are simple.;T@o; ; [ I"require 'benchmark' ;TI" ;TI"*a = (1..100000).map { rand(100000) } ;TI" ;TI"Benchmark.bm(10) do |b| ;TI"& b.report("Sort") { a.sort } ;TI"3 b.report("Sort by") { a.sort_by { |a| a } } ;TI" end ;T; 0o; ; [I"produces:;T@o; ; [I",user system total real ;TI"=Sort 0.180000 0.000000 0.180000 ( 0.175469) ;TI"=Sort by 1.980000 0.040000 2.020000 ( 2.013586) ;T; 0o; ; [I"JHowever, consider the case where comparing the keys is a non-trivial ;TI"Ioperation. The following code sorts some files on modification time ;TI".using the basic sort method.;T@o; ; [I"files = Dir["*"] ;TI"Lsorted = files.sort { |a, b| File.new(a).mtime <=> File.new(b).mtime } ;TI"2sorted #=> ["mon", "tues", "wed", "thurs"] ;T; 0o; ; [ I"FThis sort is inefficient: it generates two new File ;TI"Hobjects during every comparison. A slightly better technique is to ;TI"Juse the Kernel#test method to generate the modification ;TI"times directly.;T@o; ; [ I"files = Dir["*"] ;TI""sorted = files.sort { |a, b| ;TI"# test(?M, a) <=> test(?M, b) ;TI"} ;TI"2sorted #=> ["mon", "tues", "wed", "thurs"] ;T; 0o; ; [ I"HThis still generates many unnecessary Time objects. A ;TI"Fmore efficient technique is to cache the sort keys (modification ;TI"Etimes in this case) before the sort. Perl users often call this ;TI"Aapproach a Schwartzian Transform, after Randal Schwartz. We ;TI"Aconstruct a temporary array, where each element is an array ;TI"Jcontaining our sort key along with the filename. We sort this array, ;TI"3and then extract the filename from the result.;T@o; ; [ I"%sorted = Dir["*"].collect { |f| ;TI" [test(?M, f), f] ;TI"!}.sort.collect { |f| f[1] } ;TI"2sorted #=> ["mon", "tues", "wed", "thurs"] ;T; 0o; ; [I"?This is exactly what sort_by does internally.;T@o; ; [I"3sorted = Dir["*"].sort_by { |f| test(?M, f) } ;TI"1sorted #=> ["mon", "tues", "wed", "thurs"];T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"]enum.sort_by { |obj| block } -> array enum.sort_by -> an_enumerator ;T0[I"();T@\FI"Enumerable;TcRDoc::NormalModule00PK#]E* any%3f-i.rinu[U:RDoc::AnyMethod[iI" any?:ETI"Enumerable#any?;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"JPasses each element of the collection to the given block. The method ;TI"Greturns true if the block ever returns a value other ;TI"Fthan false or nil. If the block is not ;TI"Kgiven, Ruby adds an implicit block of { |obj| obj } that ;TI"Iwill cause #any? to return +true+ if at least one of the collection ;TI"%members is not +false+ or +nil+.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"@%w[ant bear cat].any? { |word| word.length >= 3 } #=> true ;TI"@%w[ant bear cat].any? { |word| word.length >= 4 } #=> true ;TI"?[nil, true, 99].any? #=> true;T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"4enum.any? [{ |obj| block }] -> true or false ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]|]Ǻslice_before-i.rinu[U:RDoc::AnyMethod[iI"slice_before:ETI"Enumerable#slice_before;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"6Creates an enumerator for each chunked elements. ;TI"EThe beginnings of chunks are defined by _pattern_ and the block.;To:RDoc::Markup::BlankLineo; ; [I"PIf _pattern_ === _elt_ returns true or the block ;TI"Nreturns true for the element, the element is beginning of a ;TI" chunk.;T@o; ; [I"SThe === and _block_ is called from the first element to the last ;TI"Eelement of _enum_. The result for the first element is ignored.;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"3enum.slice_before(pattern).each { |ary| ... } ;TI"9enum.slice_before { |elt| bool }.each { |ary| ... } ;TI"Oenum.slice_before(initial_state) { |elt, state| bool }.each { |ary| ... } ;T: @format0o; ; [I"BOther methods of the Enumerator class and Enumerable module, ;TI"(such as map, etc., are also usable.;T@o; ; [I"IFor example, iteration over ChangeLog entries can be implemented as ;TI" follows:;T@o; ; [I"'# iterate over ChangeLog entries. ;TI"open("ChangeLog") { |f| ;TI"0 f.slice_before(/\A\S/).each { |e| pp e } ;TI"} ;TI" ;TI"B# same as above. block is used instead of pattern argument. ;TI"open("ChangeLog") { |f| ;TI"C f.slice_before { |line| /\A\S/ === line }.each { |e| pp e } ;TI"} ;T; 0o; ; [I"@"svn proplist -R" produces multiline output for each file. ;TI"$They can be chunked as follows:;T@o; ; [ I"@IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) { |f| ;TI"? f.lines.slice_before(/\AProp/).each { |lines| p lines } ;TI"} ;TI"E#=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"] ;TI"># ["Properties on 'goruby.c':\n", " svn:eol-style\n"] ;TI"T# ["Properties on 'complex.c':\n", " svn:mime-type\n", " svn:eol-style\n"] ;TI"@# ["Properties on 'regparse.c':\n", " svn:eol-style\n"] ;TI" # ... ;T; 0o; ; [ I"BIf the block needs to maintain state over multiple elements, ;TI""local variables can be used. ;TI"OFor example, three or more consecutive increasing numbers can be squashed ;TI"as follows:;T@o; ; [I"a = [0, 2, 3, 4, 6, 7, 9] ;TI"prev = a[0] ;TI"p a.slice_before { |e| ;TI" prev, prev2 = e, prev ;TI" prev2 + 1 != e ;TI"}.map { |es| ;TI"@ es.length <= 2 ? es.join(",") : "#{es.first}-#{es.last}" ;TI"}.join(",") ;TI"#=> "0,2-4,6,7,9" ;T; 0o; ; [ I"CHowever local variables are not appropriate to maintain state ;TI"5if the result enumerator is used twice or more. ;TI"QIn such a case, the last state of the 1st +each+ is used in the 2nd +each+. ;TI"EThe _initial_state_ argument can be used to avoid this problem. ;TI"3If non-nil value is given as _initial_state_, ;TI"Kit is duplicated for each +each+ method invocation of the enumerator. ;TI"FThe duplicated object is passed to 2nd argument of the block for ;TI"+slice_before+ method.;T@o; ; [ I"D# Word wrapping. This assumes all characters have same width. ;TI"#def wordwrap(words, maxwidth) ;TI"O # if cols is a local variable, 2nd "each" may start with non-zero cols. ;TI", words.slice_before(cols: 0) { |w, h| ;TI"( h[:cols] += 1 if h[:cols] != 0 ;TI" h[:cols] += w.length ;TI" if maxwidth < h[:cols] ;TI" h[:cols] = w.length ;TI" true ;TI" else ;TI" false ;TI" end ;TI" } ;TI" end ;TI"#text = (1..20).to_a.join(" ") ;TI",enum = wordwrap(text.split(/\s+/), 10) ;TI"puts "-"*10 ;TI"*enum.each { |ws| puts ws.join(" ") } ;TI"puts "-"*10 ;TI"#=> ---------- ;TI"# 1 2 3 4 5 ;TI"# 6 7 8 9 10 ;TI"# 11 12 13 ;TI"# 14 15 16 ;TI"# 17 18 19 ;TI" # 20 ;TI"# ---------- ;T; 0o; ; [I"Dmbox contains series of mails which start with Unix From line. ;TI"BSo each mail can be extracted by slice before Unix From line.;T@o; ; [!I"# parse mbox ;TI"open("mbox") { |f| ;TI" f.slice_before { |line| ;TI"" line.start_with? "From " ;TI" }.each { |mail| ;TI" unix_from = mail.shift ;TI" i = mail.index("\n") ;TI" header = mail[0...i] ;TI" body = mail[(i+1)..-1] ;TI"' body.pop if body.last == "\n" ;TI"O fields = header.slice_before { |line| !" \t".include?(line[0]) }.to_a ;TI" p unix_from ;TI" pp fields ;TI" pp body ;TI" } ;TI"} ;TI" ;TI"M# split mails in mbox (slice before Unix From line after an empty line) ;TI"open("mbox") { |f| ;TI"- f.slice_before(emp: true) { |line, h| ;TI" prevemp = h[:emp] ;TI" h[:emp] = line == "\n" ;TI". prevemp && line.start_with?("From ") ;TI" }.each { |mail| ;TI"' mail.pop if mail.last == "\n" ;TI" pp mail ;TI" } ;TI"};T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"enum.slice_before(pattern) -> an_enumerator enum.slice_before { |elt| bool } -> an_enumerator enum.slice_before(initial_state) { |elt, state| bool } -> an_enumerator ;T0[I"(p1 = v1);T@FI"Enumerable;TcRDoc::NormalModule00PK#]Cdpartition-i.rinu[U:RDoc::AnyMethod[iI"partition:ETI"Enumerable#partition;TF: publico:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I">Returns two arrays, the first containing the elements of ;TI"Cenum for which the block evaluates to true, the second ;TI"containing the rest.;To:RDoc::Markup::BlankLineo; ; [I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim; [I"A(1..6).partition { |v| v.even? } #=> [[2, 4, 6], [1, 3, 5]];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"senum.partition { |obj| block } -> [ true_array, false_array ] enum.partition -> an_enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00PK#]xo#   find_all-i.rinu[PK#]/Hzip-i.rinu[PK#]?$&Iminmax_by-i.rinu[PK#]Y take_while-i.rinu[PK#]ڇzz chunk-i.rinu[PK#] SS Vfilter-i.rinu[PK#]  take-i.rinu[PK#]0h #reduce-i.rinu[PK#]#vi *to_a-i.rinu[PK#]  -first-i.rinu[PK#]ư 0grep-i.rinu[PK#]e 4group_by-i.rinu[PK#]{{8slice_after-i.rinu[PK#]G  >sort-i.rinu[PK#] Binject-i.rinu[PK#]+WD Jnone%3f-i.rinu[PK#]NE Nmin_by-i.rinu[PK#] kQeach_with_object-i.rinu[PK#]kbbUcdesc-Enumerable.rinu[PK#] ll\include%3f-i.rinu[PK#]ּ%vv`_filter_map-i.rinu[PK#]s cdrop-i.rinu[PK#]Ja{ aecollect-i.rinu[PK#]4]QQ rhlazy-i.rinu[PK#]#M mtally-i.rinu[PK#]m$sreverse_each-i.rinu[PK#]Ow .vone%3f-i.rinu[PK#]'izmax-i.rinu[PK#]ȯ^!!}collect_concat-i.rinu[PK#]B select-i.rinu[PK#]HD0each_cons-i.rinu[PK#]Jksum-i.rinu[PK#]4;; lcount-i.rinu[PK#]lL all%3f-i.rinu[PK#]f ݔchunk_while-i.rinu[PK#] &uniq-i.rinu[PK#]uM9min-i.rinu[PK#]VZ \flat_map-i.rinu[PK#]4Ofind_index-i.rinu[PK#](ӵdrop_while-i.rinu[PK#]Fl%map-i.rinu[PK#] *compact-i.rinu[PK#];teach_slice-i.rinu[PK#] Mreject-i.rinu[PK#]>Gjjmember%3f-i.rinu[PK#]z_ 6detect-i.rinu[PK#]0 each_entry-i.rinu[PK#]]ۘ to_set-i.rinu[PK#][qqeach_with_index-i.rinu[PK#]#!! lto_h-i.rinu[PK#]0<< cycle-i.rinu[PK#]᯲w <find-i.rinu[PK#]KQQ  minmax-i.rinu[PK#]b b slice_when-i.rinu[PK#] _ 9entries-i.rinu[PK#]Yl  chain-i.rinu[PK#]4c Xmax_by-i.rinu[PK#]Z /grep_v-i.rinu[PK#]v  sort_by-i.rinu[PK#]E* Hany%3f-i.rinu[PK#]|]Ǻ[slice_before-i.rinu[PK#]CdVpartition-i.rinu[PK>>s