ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- find_all-i.ri000064400000001642152373163160007110 0ustar00U:RDoc::AnyMethod[iI" find_all:ETI"Enumerable#find_all;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_below0I";select {|element| ... } -> array select -> enumerator ;T0[[I" select;T@ [I" filter;T@ I"();T@FI"Enumerable;TcRDoc::NormalModule00zip-i.ri000064400000004774152373163160006153 0ustar00U:RDoc::AnyMethod[iI"zip:ETI"Enumerable#zip;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"LWith no block given, returns a new array +new_array+ of size self.size ;TI" whose elements are arrays. ;TI"-Each nested array new_array[n] ;TI":is of size other_enums.size+1, and contains:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I" The +n+-th element of self.;To;;0; [o; ; [I"5The +n+-th element of each of the +other_enums+.;T@o; ; [I"6If all +other_enums+ and self are the same size, ;TI"Lall elements are included in the result, and there is no +nil+-filling:;T@o:RDoc::Markup::Verbatim; [I"a = [:a0, :a1, :a2, :a3] ;TI"b = [:b0, :b1, :b2, :b3] ;TI"c = [:c0, :c1, :c2, :c3] ;TI"d = a.zip(b, c) ;TI"Qd # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, :c2], [:a3, :b3, :c3]] ;TI" ;TI""f = {foo: 0, bar: 1, baz: 2} ;TI""g = {goo: 3, gar: 4, gaz: 5} ;TI""h = {hoo: 6, har: 7, haz: 8} ;TI"d = f.zip(g, h) ;TI"d # => [ ;TI"1 # [[:foo, 0], [:goo, 3], [:hoo, 6]], ;TI"1 # [[:bar, 1], [:gar, 4], [:har, 7]], ;TI"0 # [[:baz, 2], [:gaz, 5], [:haz, 8]] ;TI" # ] ;T: @format0o; ; [I"self.size with +nil+:;T@o;; [ I"a = [:a0, :a1, :a2, :a3] ;TI"b = [:b0, :b1, :b2] ;TI"c = [:c0, :c1] ;TI"d = a.zip(b, c) ;TI"Qd # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, nil], [:a3, nil, nil]] ;T;0o; ; [I";If any enumerable in other_enums is larger than self, ;TI"'its trailing elements are ignored:;T@o;; [ I"a = [:a0, :a1, :a2, :a3] ;TI"#b = [:b0, :b1, :b2, :b3, :b4] ;TI"(c = [:c0, :c1, :c2, :c3, :c4, :c5] ;TI"d = a.zip(b, c) ;TI"Qd # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, :c2], [:a3, :b3, :c3]] ;T;0o; ; [I"HWhen a block is given, calls the block with each of the sub-arrays ;TI"$(formed as above); returns nil:;T@o;; [ I"a = [:a0, :a1, :a2, :a3] ;TI"b = [:b0, :b1, :b2, :b3] ;TI"c = [:c0, :c1, :c2, :c3] ;TI"4a.zip(b, c) {|sub_array| p sub_array} # => nil ;T;0o; ; [I" Output:;T@o;; [ I"[:a0, :b0, :c0] ;TI"[:a1, :b1, :c1] ;TI"[:a2, :b2, :c2] ;TI"[:a3, :b3, :c3];T;0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Hzip(*other_enums) -> array zip(*other_enums) {|array| ... } -> nil ;T0[I" (*args);T@\FI"Enumerable;TcRDoc::NormalModule00minmax_by-i.ri000064400000001706152373163160007324 0ustar00U:RDoc::AnyMethod[iI"minmax_by:ETI"Enumerable#minmax_by;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"7Returns a 2-element array containing the elements ;TI" [4, 1] ;TI"5%w[a b c d].minmax_by {|element| -element.ord } ;TI"# => ["d", "a"] ;TI"?{foo: 0, bar: 1, baz: 2}.minmax_by {|key, value| -value } ;TI"!# => [[:baz, 2], [:foo, 0]] ;TI"([].minmax_by {|element| -element } ;TI"# => [nil, nil] ;T: @format0o; ; [I"0Returns an Enumerator if no block is given.;T@o; ; [I"(Related: #max_by, #minmax, #min_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"_minmax_by {|element| ... } -> [minimum, maximum] minmax_by -> enumerator ;T0[I"();T@ FI"Enumerable;TcRDoc::NormalModule00take_while-i.ri000064400000001464152373163160007456 0ustar00U:RDoc::AnyMethod[iI"take_while:ETI"Enumerable#take_while;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"CCalls the block with successive elements as long as the block ;TI"returns a truthy value; ;TI"7returns an array of all elements up to that point:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"/(1..4).take_while{|i| i < 3 } # => [1, 2] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"?h.take_while{|element| key, value = *element; value < 2 } ;TI"!# => [[:foo, 0], [:bar, 1]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Ttake_while {|element| ... } -> array take_while -> enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00chunk-i.ri000064400000007651152373163160006456 0ustar00U:RDoc::AnyMethod[iI" chunk:ETI"Enumerable#chunk;TF: privateo:RDoc::Markup::Document: @parts[&o:RDoc::Markup::Paragraph; [I"PEach element in the returned enumerator is a 2-element array consisting of:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"#A value returned by the block.;To;;0; [o; ; [I"RAn array ("chunk") containing the element for which that value was returned, ;TI"Land all following elements for which the block returned the same value:;T@o; ; [I" So that:;T@o; ; ;;[o;;0; [o; ; [I"DEach block return value that is different from its predecessor ;TI"begins a new chunk.;To;;0; [o; ; [I"AEach block return value that is the same as its predecessor ;TI"continues the same chunk.;T@o; ; [I" Example:;T@o:RDoc::Markup::Verbatim; [ I"De = (0..10).chunk {|i| (i / 3).floor } # => # ;TI" # The enumerator elements. ;TI" e.next # => [0, [0, 1, 2]] ;TI" e.next # => [1, [3, 4, 5]] ;TI" e.next # => [2, [6, 7, 8]] ;TI"e.next # => [3, [9, 10]] ;T: @format0o; ; [I"T\Method +chunk+ is especially useful for an enumerable that is already sorted. ;TI"QThis example counts words for each initial letter in a large array of words:;T@o;; [ I")# Get sorted words from a web page. ;TI"[url = 'https://raw.githubusercontent.com/eneko/data-repository/master/data/words.txt' ;TI"&words = URI::open(url).readlines ;TI")# Make chunks, one for each letter. ;TI"Fe = words.chunk {|word| word.upcase[0] } # => # ;TI" # Display 'A' through 'F'. ;TI"Ae.each {|c, words| p [c, words.length]; break if c == 'F' } ;T;0o; ; [I" Output:;T@o;; [ I"["A", 17096] ;TI"["B", 11070] ;TI"["C", 19901] ;TI"["D", 10896] ;TI"["E", 8736] ;TI"["F", 6860] ;T;0o; ; [I"IYou can use the special symbol :_alone to force an element ;TI"!into its own separate chuck:;T@o;; [I"a = [0, 0, 1, 1] ;TI"0e = a.chunk{|i| i.even? ? :_alone : true } ;TI"Be.to_a # => [[:_alone, [0]], [:_alone, [0]], [true, [1, 1]]] ;T;0o; ; [I"OFor example, you can put each line that contains a URL into its own chunk:;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"BYou can use the special symbol :_separator or +nil+ ;TI"Cto force an element to be ignored (not included in any chunk):;T@o;; [I"a = [0, 0, -1, 1, 1] ;TI"2e = a.chunk{|i| i < 0 ? :_separator : true } ;TI"2e.to_a # => [[true, [0, 0]], [true, [1, 1]]] ;T;0o; ; [I"0Note that the separator does end the chunk:;T@o;; [I"a = [0, 0, -1, 1, -1, 1] ;TI"2e = a.chunk{|i| i < 0 ? :_separator : true } ;TI" [[true, [0, 0]], [true, [1]], [true, [1]]] ;T;0o; ; [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;0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"(chunk {|array| ... } -> enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00filter-i.ri000064400000001523152373163160006623 0ustar00U: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;Ttake-i.ri000064400000001110152373163160006252 0ustar00U:RDoc::AnyMethod[iI" take:ETI"Enumerable#take;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"BFor non-negative integer +n+, returns the first +n+ elements:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"r = (1..4) ;TI"r.take(2) # => [1, 2] ;TI"r.take(0) # => [] ;TI" ;TI"*h = {foo: 0, bar: 1, baz: 2, bat: 3} ;TI"*h.take(2) # => [[:foo, 0], [:bar, 1]];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"take(n) -> array ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00reduce-i.ri000064400000012744152373163160006614 0ustar00U:RDoc::AnyMethod[iI" reduce:ETI"Enumerable#reduce;TF: privateo:RDoc::Markup::Document: @parts[7o:RDoc::Markup::Paragraph; [I"7Returns an object formed from operands via either:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I" A method named by +symbol+.;To;;0; [o; ; [I"-A block to which each operand is passed.;T@o; ; [I")With method-name argument +symbol+, ;TI"(combines operands using the method:;T@o:RDoc::Markup::Verbatim; [ I"%# Sum, without initial_operand. ;TI"#(1..4).inject(:+) # => 10 ;TI""# Sum, with initial_operand. ;TI"#(1..4).inject(10, :+) # => 20 ;T: @format0o; ; [I"4With a block, passes each operand to the block:;T@o;; [ I"0# Sum of squares, without initial_operand. ;TI"4(1..4).inject {|sum, n| sum + n*n } # => 30 ;TI"-# Sum of squares, with initial_operand. ;TI"4(1..4).inject(2) {|sum, n| sum + n*n } # => 32 ;T;0o; ; [I"Operands;T@o; ; [I"1If argument +initial_operand+ is not given, ;TI"Bthe operands for +inject+ are simply the elements of +self+. ;TI"&Example calls and their operands:;T@o; ; ;;[ o;;0; [o; ; : NOTE;[o;;[I"(1..4).inject(:+);T; [o; ; [I"[1, 2, 3, 4].;To;;0; [o; ; ;;[o;;[I" (1...4).inject(:+);T; [o; ; [I"[1, 2, 3].;To;;0; [o; ; ;;[o;;[I"#('a'..'d').inject(:+);T; [o; ; [I"#['a', 'b', 'c', 'd'].;To;;0; [o; ; ;;[o;;[I"$('a'...'d').inject(:+);T; [o; ; [I"['a', 'b', 'c'].;T@o; ; [I"QExamples with first operand (which is self.first) of various types:;T@o;; [ I"# Integer. ;TI".(1..4).inject(:+) # => 10 ;TI"# Float. ;TI"0[1.0, 2, 3, 4].inject(:+) # => 10.0 ;TI"# Character. ;TI"2('a'..'d').inject(:+) # => "abcd" ;TI"# Complex. ;TI"2[Complex(1, 2), 3, 4].inject(:+) # => (8+2i) ;T;0o; ; [I"-If argument +initial_operand+ is given, ;TI"Kthe operands for +inject+ are that value plus the elements of +self+. ;TI""Example calls their operands:;T@o; ; ;;[ o;;0; [o; ; ;;[o;;[I"#(1..4).inject(10, :+);T; [o; ; [I"[10, 1, 2, 3, 4].;To;;0; [o; ; ;;[o;;[I"$(1...4).inject(10, :+);T; [o; ; [I"[10, 1, 2, 3].;To;;0; [o; ; ;;[o;;[I"(('a'..'d').inject('e', :+);T; [o; ; [I"(['e', 'a', 'b', 'c', 'd'].;To;;0; [o; ; ;;[o;;[I")('a'...'d').inject('e', :+);T; [o; ; [I"#['e', 'a', 'b', 'c'].;T@o; ; [I"6Examples with +initial_operand+ of various types:;T@o;; [I"# Integer. ;TI"0(1..4).inject(2, :+) # => 12 ;TI"# Float. ;TI"2(1..4).inject(2.0, :+) # => 12.0 ;TI"# String. ;TI"7('a'..'d').inject('foo', :+) # => "fooabcd" ;TI"# Array. ;TI"B%w[a b c].inject(['x'], :push) # => ["x", "a", "b", "c"] ;TI"# Complex. ;TI"5(1..4).inject(Complex(2, 2), :+) # => (12+2i) ;T;0o; ; [I"(Combination by Given \Method;T@o; ; [I"4If the method-name argument +symbol+ is given, ;TI".the operands are combined by that method:;T@o; ; ;;[ o;;0; [o; ; [I"0The first and second operands are combined.;To;;0; [o; ; [I"4That result is combined with the third operand.;To;;0; [o; ; [I"5That result is combined with the fourth operand.;To;;0; [o; ; [I"And so on.;T@o; ; [I"JThe return value from +inject+ is the result of the last combination.;T@o; ; [I" 10 ;T;0o; ; [I"#Examples with various methods:;T@o;; [I"# Integer addition. ;TI".(1..4).inject(:+) # => 10 ;TI"# Integer multiplication. ;TI".(1..4).inject(:*) # => 24 ;TI"&# Character range concatenation. ;TI"2('a'..'d').inject('', :+) # => "abcd" ;TI"## String array concatenation. ;TI"7%w[foo bar baz].inject('', :+) # => "foobarbaz" ;TI"# Hash update. ;TI"@h = [{foo: 0, bar: 1}, {baz: 2}, {bat: 3}].inject(:update) ;TI"1h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3} ;TI")# Hash conversion to nested arrays. ;TI",h = {foo: 0, bar: 1}.inject([], :push) ;TI"#h # => [[:foo, 0], [:bar, 1]] ;T;0o; ; [I"&Combination by Given Block;T@o; ; [I"?If a block is given, the operands are passed to the block:;T@o; ; ;;[ o;;0; [o; ; [I"9The first call passes the first and second operands.;To;;0; [o; ; [I":The second call passes the result of the first call, ;TI""along with the third operand.;To;;0; [o; ; [I":The third call passes the result of the second call, ;TI"#along with the fourth operand.;To;;0; [o; ; [I"And so on.;T@o; ; [I"QThe return value from +inject+ is the return value from the last block call.;T@o; ; [I")This call to +inject+ gives a block ;TI"Bthat writes the memo and element, and also sums the elements:;T@o;; [ I"&(1..4).inject do |memo, element| ;TI". p "Memo: #{memo}; element: #{element}" ;TI" memo + element ;TI"end # => 10 ;T;0o; ; [I" Output:;T@o;; [I""Memo: 1; element: 2" ;TI""Memo: 3; element: 3" ;TI""Memo: 6; element: 4" ;T;0o; ; [I"9Enumerable#reduce is an alias for Enumerable#inject.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I"(p1 = v1, p2 = v2);T@FI"Enumerable;TcRDoc::NormalModule0[@ FI" inject;Tto_a-i.ri000064400000001017152373163160006256 0ustar00U:RDoc::AnyMethod[iI" to_a:ETI"Enumerable#to_a;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"5Returns an array containing the items in +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"&(0..4).to_a # => [0, 1, 2, 3, 4] ;T: @format0o; ; [I"8Enumerable#entries is an alias for Enumerable#to_a.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"to_a -> array ;T0[[I" entries;T@ I" (*args);T@FI"Enumerable;TcRDoc::NormalModule00first-i.ri000064400000002151152373163160006463 0ustar00U:RDoc::AnyMethod[iI" first:ETI"Enumerable#first;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"+Returns the first element or elements.;To:RDoc::Markup::BlankLineo; ; [I"LWith no argument, returns the first element, or +nil+ if there is none:;T@o:RDoc::Markup::Verbatim; [ I"+(1..4).first # => 1 ;TI"-%w[a b c].first # => "a" ;TI"3{foo: 1, bar: 1, baz: 2}.first # => [:foo, 1] ;TI"-[].first # => nil ;T: @format0o; ; [I"1With integer argument +n+, returns an array ;TI"2containing the first +n+ elements that exist:;T@o; ; [ I"3(1..4).first(2) # => [1, 2] ;TI"<%w[a b c d].first(3) # => ["a", "b", "c"] ;TI"A%w[a b c d].first(50) # => ["a", "b", "c", "d"] ;TI"C{foo: 1, bar: 1, baz: 2}.first(2) # => [[:foo, 1], [:bar, 1]] ;TI".[].first(2) # => [];T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"2first -> element or nil first(n) -> array ;T0[I" (*args);T@#FI"Enumerable;TcRDoc::NormalModule00grep-i.ri000064400000002163152373163160006274 0ustar00U:RDoc::AnyMethod[iI" grep:ETI"Enumerable#grep;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"WReturns an array of objects based elements of +self+ that match the given pattern.;To:RDoc::Markup::BlankLineo; ; [I"CWith no block given, returns an array containing each element ;TI"6for which pattern === element is +true+:;T@o:RDoc::Markup::Verbatim; [ I"&a = ['foo', 'bar', 'car', 'moo'] ;TI"8a.grep(/ar/) # => ["bar", "car"] ;TI"<(1..10).grep(3..8) # => [3, 4, 5, 6, 7, 8] ;TI"0['a', 'b', 0, 1].grep(Integer) # => [0, 1] ;T: @format0o; ; [I"With a block given, ;TI"Ucalls the block with each matching element and returns an array containing each ;TI""object returned by the block:;T@o; ; [I"&a = ['foo', 'bar', 'car', 'moo'] ;TI"Ba.grep(/ar/) {|element| element.upcase } # => ["BAR", "CAR"] ;T; 0o; ; [I"Related: #grep_v.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Dgrep(pattern) -> array grep(pattern) {|element| ... } -> array ;T0[I" (p1);T@%FI"Enumerable;TcRDoc::NormalModule00group_by-i.ri000064400000002005152373163160007160 0ustar00U:RDoc::AnyMethod[iI" group_by:ETI"Enumerable#group_by;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"'With a block given returns a hash:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"/Each key is a return value from the block.;To;;0; [o; ; [I"TEach value is an array of those elements for which the block returned that key.;T@o; ; [I"Examples:;T@o:RDoc::Markup::Verbatim; [ I"$g = (1..6).group_by {|i| i%3 } ;TI".g # => {1=>[1, 4], 2=>[2, 5], 0=>[3, 6]} ;TI"*h = {foo: 0, bar: 1, baz: 0, bat: 1} ;TI"*g = h.group_by {|key, value| value } ;TI"Cg # => {0=>[[:foo, 0], [:baz, 0]], 1=>[[:bar, 1], [:bat, 1]]} ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Ogroup_by {|element| ... } -> hash group_by -> enumerator ;T0[I"();T@(FI"Enumerable;TcRDoc::NormalModule00slice_after-i.ri000064400000003173152373163160007621 0ustar00U: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::NormalModule00sort-i.ri000064400000003021152373163160006320 0ustar00U:RDoc::AnyMethod[iI" sort:ETI"Enumerable#sort;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"@Returns an array containing the sorted elements of +self+. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLineo; ; [I",With no block given, the sort compares ;TI"1using the elements' own method <=>:;T@o:RDoc::Markup::Verbatim; [I"=%w[b c a d].sort # => ["a", "b", "c", "d"] ;TI"J{foo: 0, bar: 1, baz: 2}.sort # => [[:bar, 1], [:baz, 2], [:foo, 0]] ;T: @format0o; ; [I"JWith a block given, comparisons in the block determine the ordering. ;TI"HThe block is called with two elements +a+ and +b+, and must return:;T@o:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"*A negative integer if a < b.;To;;0; [o; ; [I"Zero if a == b.;To;;0; [o; ; [I"*A positive integer if a > b.;T@o; ; [I"Examples:;T@o; ; [ I"a = %w[b c a d] ;TI"8a.sort {|a, b| b <=> a } # => ["d", "c", "b", "a"] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"Eh.sort {|a, b| b <=> a } # => [[:foo, 0], [:baz, 2], [:bar, 1]] ;T; 0o; ; [I">See also #sort_by. It implements a Schwartzian transform ;TI"Ewhich is useful when key computation or comparison is expensive.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"=sort -> array sort {|a, b| ... } -> array ;T0[I"();T@:FI"Enumerable;TcRDoc::NormalModule00inject-i.ri000064400000013215152373163160006613 0ustar00U:RDoc::AnyMethod[iI" inject:ETI"Enumerable#inject;TF: privateo:RDoc::Markup::Document: @parts[7o:RDoc::Markup::Paragraph; [I"7Returns an object formed from operands via either:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I" A method named by +symbol+.;To;;0; [o; ; [I"-A block to which each operand is passed.;T@o; ; [I")With method-name argument +symbol+, ;TI"(combines operands using the method:;T@o:RDoc::Markup::Verbatim; [ I"%# Sum, without initial_operand. ;TI"#(1..4).inject(:+) # => 10 ;TI""# Sum, with initial_operand. ;TI"#(1..4).inject(10, :+) # => 20 ;T: @format0o; ; [I"4With a block, passes each operand to the block:;T@o;; [ I"0# Sum of squares, without initial_operand. ;TI"4(1..4).inject {|sum, n| sum + n*n } # => 30 ;TI"-# Sum of squares, with initial_operand. ;TI"4(1..4).inject(2) {|sum, n| sum + n*n } # => 32 ;T;0o; ; [I"Operands;T@o; ; [I"1If argument +initial_operand+ is not given, ;TI"Bthe operands for +inject+ are simply the elements of +self+. ;TI"&Example calls and their operands:;T@o; ; ;;[ o;;0; [o; ; : NOTE;[o;;[I"(1..4).inject(:+);T; [o; ; [I"[1, 2, 3, 4].;To;;0; [o; ; ;;[o;;[I" (1...4).inject(:+);T; [o; ; [I"[1, 2, 3].;To;;0; [o; ; ;;[o;;[I"#('a'..'d').inject(:+);T; [o; ; [I"#['a', 'b', 'c', 'd'].;To;;0; [o; ; ;;[o;;[I"$('a'...'d').inject(:+);T; [o; ; [I"['a', 'b', 'c'].;T@o; ; [I"QExamples with first operand (which is self.first) of various types:;T@o;; [ I"# Integer. ;TI".(1..4).inject(:+) # => 10 ;TI"# Float. ;TI"0[1.0, 2, 3, 4].inject(:+) # => 10.0 ;TI"# Character. ;TI"2('a'..'d').inject(:+) # => "abcd" ;TI"# Complex. ;TI"2[Complex(1, 2), 3, 4].inject(:+) # => (8+2i) ;T;0o; ; [I"-If argument +initial_operand+ is given, ;TI"Kthe operands for +inject+ are that value plus the elements of +self+. ;TI""Example calls their operands:;T@o; ; ;;[ o;;0; [o; ; ;;[o;;[I"#(1..4).inject(10, :+);T; [o; ; [I"[10, 1, 2, 3, 4].;To;;0; [o; ; ;;[o;;[I"$(1...4).inject(10, :+);T; [o; ; [I"[10, 1, 2, 3].;To;;0; [o; ; ;;[o;;[I"(('a'..'d').inject('e', :+);T; [o; ; [I"(['e', 'a', 'b', 'c', 'd'].;To;;0; [o; ; ;;[o;;[I")('a'...'d').inject('e', :+);T; [o; ; [I"#['e', 'a', 'b', 'c'].;T@o; ; [I"6Examples with +initial_operand+ of various types:;T@o;; [I"# Integer. ;TI"0(1..4).inject(2, :+) # => 12 ;TI"# Float. ;TI"2(1..4).inject(2.0, :+) # => 12.0 ;TI"# String. ;TI"7('a'..'d').inject('foo', :+) # => "fooabcd" ;TI"# Array. ;TI"B%w[a b c].inject(['x'], :push) # => ["x", "a", "b", "c"] ;TI"# Complex. ;TI"5(1..4).inject(Complex(2, 2), :+) # => (12+2i) ;T;0o; ; [I"(Combination by Given \Method;T@o; ; [I"4If the method-name argument +symbol+ is given, ;TI".the operands are combined by that method:;T@o; ; ;;[ o;;0; [o; ; [I"0The first and second operands are combined.;To;;0; [o; ; [I"4That result is combined with the third operand.;To;;0; [o; ; [I"5That result is combined with the fourth operand.;To;;0; [o; ; [I"And so on.;T@o; ; [I"JThe return value from +inject+ is the result of the last combination.;T@o; ; [I" 10 ;T;0o; ; [I"#Examples with various methods:;T@o;; [I"# Integer addition. ;TI".(1..4).inject(:+) # => 10 ;TI"# Integer multiplication. ;TI".(1..4).inject(:*) # => 24 ;TI"&# Character range concatenation. ;TI"2('a'..'d').inject('', :+) # => "abcd" ;TI"## String array concatenation. ;TI"7%w[foo bar baz].inject('', :+) # => "foobarbaz" ;TI"# Hash update. ;TI"@h = [{foo: 0, bar: 1}, {baz: 2}, {bat: 3}].inject(:update) ;TI"1h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3} ;TI")# Hash conversion to nested arrays. ;TI",h = {foo: 0, bar: 1}.inject([], :push) ;TI"#h # => [[:foo, 0], [:bar, 1]] ;T;0o; ; [I"&Combination by Given Block;T@o; ; [I"?If a block is given, the operands are passed to the block:;T@o; ; ;;[ o;;0; [o; ; [I"9The first call passes the first and second operands.;To;;0; [o; ; [I":The second call passes the result of the first call, ;TI""along with the third operand.;To;;0; [o; ; [I":The third call passes the result of the second call, ;TI"#along with the fourth operand.;To;;0; [o; ; [I"And so on.;T@o; ; [I"QThe return value from +inject+ is the return value from the last block call.;T@o; ; [I")This call to +inject+ gives a block ;TI"Bthat writes the memo and element, and also sums the elements:;T@o;; [ I"&(1..4).inject do |memo, element| ;TI". p "Memo: #{memo}; element: #{element}" ;TI" memo + element ;TI"end # => 10 ;T;0o; ; [I" Output:;T@o;; [I""Memo: 1; element: 2" ;TI""Memo: 3; element: 3" ;TI""Memo: 6; element: 4" ;T;0o; ; [I"9Enumerable#reduce is an alias for Enumerable#inject.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"inject(symbol) -> object inject(initial_operand, symbol) -> object inject {|memo, operand| ... } -> object inject(initial_operand) {|memo, operand| ... } -> object ;T0[[I" reduce;T@ I"(p1 = v1, p2 = v2);T@FI"Enumerable;TcRDoc::NormalModule00none%3f-i.ri000064400000003423152373163160006574 0ustar00U:RDoc::AnyMethod[iI" none?:ETI"Enumerable#none?;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"8Returns whether no element meets a given criterion.;To:RDoc::Markup::BlankLineo; ; [I"$With no argument and no block, ;TI"*returns whether no element is truthy:;T@o:RDoc::Markup::Verbatim; [ I"'(1..4).none? # => false ;TI"&[nil, false].none? # => true ;TI"'{foo: 0}.none? # => false ;TI"'{foo: 0, bar: 1}.none? # => false ;TI"&[].none? # => true ;T: @format0o; ; [I"+With argument +pattern+ and no block, ;TI"/returns whether for no element +element+, ;TI""pattern === element:;T@o; ; [ I"5[nil, false, 1.1].none?(Integer) # => true ;TI"6%w[bar baz bat bam].none?(/m/) # => false ;TI"5%w[bar baz bat bam].none?(/foo/) # => true ;TI"5%w[bar baz bat bam].none?('ba') # => true ;TI"5{foo: 0, bar: 1, baz: 2}.none?(Hash) # => true ;TI"6{foo: 0}.none?(Array) # => false ;TI"5[].none?(Integer) # => true ;T; 0o; ; [I"JWith a block given, returns whether the block returns a truthy value ;TI"for no element:;T@o; ; [ I"I(1..4).none? {|element| element < 1 } # => true ;TI"J(1..4).none? {|element| element < 2 } # => false ;TI"I{foo: 0, bar: 1, baz: 2}.none? {|key, value| value < 0 } # => true ;TI"I{foo: 0, bar: 1, baz: 2}.none? {|key, value| value < 1 } # => false ;T; 0o; ; [I""Related: #one?, #all?, #any?.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"}none? -> true or false none?(pattern) -> true or false none? {|element| ... } -> true or false ;T0[I" (*args);T@5FI"Enumerable;TcRDoc::NormalModule00min_by-i.ri000064400000003055152373163160006615 0ustar00U:RDoc::AnyMethod[iI" min_by:ETI"Enumerable#min_by;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"IReturns the elements for which the block returns the minimum values.;To:RDoc::Markup::BlankLineo; ; [I")With a block given and no argument, ;TI"Greturns the element for which the block returns the minimum value:;T@o:RDoc::Markup::Verbatim; [ I"C(1..4).min_by {|element| -element } # => 4 ;TI"E%w[a b c d].min_by {|element| -element.ord } # => "d" ;TI"K{foo: 0, bar: 1, baz: 2}.min_by {|key, value| -value } # => [:baz, 2] ;TI"E[].min_by {|element| -element } # => nil ;T: @format0o; ; [I"AWith a block given and positive integer argument +n+ given, ;TI"2returns an array containing the +n+ elements ;TI"0for which the block returns minimum values:;T@o; ; [ I",(1..4).min_by(2) {|element| -element } ;TI"# => [4, 3] ;TI"5%w[a b c d].min_by(2) {|element| -element.ord } ;TI"# => ["d", "c"] ;TI"?{foo: 0, bar: 1, baz: 2}.min_by(2) {|key, value| -value } ;TI"!# => [[:baz, 2], [:bar, 1]] ;TI"([].min_by(2) {|element| -element } ;TI" # => [] ;T; 0o; ; [I"0Returns an Enumerator if no block is given.;T@o; ; [I"%Related: #min, #minmax, #max_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"min_by {|element| ... } -> element min_by(n) {|element| ... } -> array min_by -> enumerator min_by(n) -> enumerator ;T0[I" (*args);T@.FI"Enumerable;TcRDoc::NormalModule00each_with_object-i.ri000064400000001512152373163160010615 0ustar00U:RDoc::AnyMethod[iI"each_with_object:ETI" Enumerable#each_with_object;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"ECalls the block once for each element, passing both the element ;TI"and the given object:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"K(1..4).each_with_object([]) {|i, a| a.push(i**2) } # => [1, 4, 9, 16] ;TI"Fh.each_with_object({}) {|element, h| k, v = *element; h[v] = k } ;TI"&# => {0=>:foo, 1=>:bar, 2=>:baz} ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"each_with_object(object) { |(*args), memo_object| ... } -> object each_with_object(object) -> enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00cdesc-Enumerable.ri000064400000024502152373163160010250 0ustar00U:RDoc::NormalModule[iI"Enumerable:ET@0o:RDoc::Markup::Document: @parts[o;;[;S:RDoc::Markup::Heading: leveli: textI"What's Here;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[I"T\Module \Enumerable provides methods that are useful to a collection class for:;To:RDoc::Markup::List: @type: BULLET: @items[ o:RDoc::Markup::ListItem: @label0;[o; ;[I">{Querying}[#module-Enumerable-label-Methods+for+Querying];To;;0;[o; ;[I">{Fetching}[#module-Enumerable-label-Methods+for+Fetching];To;;0;[o; ;[I"@{Searching}[#module-Enumerable-label-Methods+for+Searching];To;;0;[o; ;[I"<{Sorting}[#module-Enumerable-label-Methods+for+Sorting];To;;0;[o; ;[I"@{Iterating}[#module-Enumerable-label-Methods+for+Iterating];To;;0;[o; ;[I";{And more....}[#module-Enumerable-label-Other+Methods];T@S; ; i; I"Methods for Querying;T@o; ;[I"_These methods return information about the \Enumerable other than the elements themselves:;T@o;;: NOTE;[ o;;[I"#include?, #member?;T;[o; ;[I"9Returns +true+ if self == object, +false+ otherwise.;To;;[I" #all?;T;[o; ;[I"RReturns +true+ if all elements meet a specified criterion; +false+ otherwise.;To;;[I" #any?;T;[o; ;[I"RReturns +true+ if any element meets a specified criterion; +false+ otherwise.;To;;[I" #none?;T;[o; ;[I"QReturns +true+ if no element meets a specified criterion; +false+ otherwise.;To;;[I" #one?;T;[o; ;[I"ZReturns +true+ if exactly one element meets a specified criterion; +false+ otherwise.;To;;[I" #count;T;[o; ;[I"$Returns the count of elements, ;TI"7based on an argument or block criterion, if given.;To;;[I" #tally;T;[o; ;[I"NReturns a new \Hash containing the counts of occurrences of each element.;T@S; ; i; I"Methods for Fetching;T@o; ;[I"MThese methods return entries from the \Enumerable, without modifying it:;T@o; ;[I"/Leading, trailing, or all elements:;To;;;;[ o;;[I"#entries, #to_a;T;[o; ;[I"Returns all elements.;To;;[I" #first;T;[o; ;[I"3Returns the first element or leading elements.;To;;[I" #take;T;[o; ;[I"4Returns a specified number of leading elements.;To;;[I" #drop;T;[o; ;[I"5Returns a specified number of trailing elements.;To;;[I"#take_while;T;[o; ;[I">Returns leading elements as specified by the given block.;To;;[I"#drop_while;T;[o; ;[I"?Returns trailing elements as specified by the given block.;T@o; ;[I"/Minimum and maximum value elements:;To;;;;[ o;;[I" #min;T;[o; ;[I"HReturns the elements whose values are smallest among the elements, ;TI"4as determined by <=> or a given block.;To;;[I" #max;T;[o; ;[I"GReturns the elements whose values are largest among the elements, ;TI"4as determined by <=> or a given block.;To;;[I" #minmax;T;[o; ;[I"MReturns a 2-element \Array containing the smallest and largest elements.;To;;[I" #min_by;T;[o; ;[I"DReturns the smallest element, as determined by the given block.;To;;[I" #max_by;T;[o; ;[I"CReturns the largest element, as determined by the given block.;To;;[I"#minmax_by;T;[o; ;[I"QReturns the smallest and largest elements, as determined by the given block.;T@o; ;[I"+Groups, slices, and partitions:;To;;;;[ o;;[I"#group_by;T;[o; ;[I">Returns a \Hash that partitions the elements into groups.;To;;[I"#partition;T;[o; ;[I"XReturns elements partitioned into two new Arrays, as determined by the given block.;To;;[I"#slice_after;T;[o; ;[I"HReturns a new \Enumerator whose entries are a partition of +self+, ;TI"7based either on a given +object+ or a given block.;To;;[I"#slice_before;T;[o; ;[I"HReturns a new \Enumerator whose entries are a partition of +self+, ;TI"7based either on a given +object+ or a given block.;To;;[I"#slice_when;T;[o; ;[I"GReturns a new \Enumerator whose entries are a partition of +self+ ;TI"based on the given block.;To;;[I" #chunk;T;[o; ;[I"LReturns elements organized into chunks as specified by the given block.;To;;[I"#chunk_while;T;[o; ;[I"LReturns elements organized into chunks as specified by the given block.;T@S; ; i; I"(Methods for Searching and Filtering;T@o; ;[I"CThese methods return elements that meet a specified criterion.;T@o;;;;[ o;;[I"#find, #detect;T;[o; ;[I".Returns an element selected by the block.;To;;[I" #find_all, #filter, #select;T;[o; ;[I",Returns elements selected by the block.;To;;[I"#find_index;T;[o; ;[I"IReturns the index of an element selected by a given object or block.;To;;[I" #reject;T;[o; ;[I"0Returns elements not rejected by the block.;To;;[I" #uniq;T;[o; ;[I".Returns elements that are not duplicates.;T@S; ; i; I"Methods for Sorting;T@o; ;[I"3These methods return elements in sorted order.;T@o;;;;[o;;[I" #sort;T;[o; ;[I"EReturns the elements, sorted by <=> or the given block.;To;;[I" #sort_by;T;[o; ;[I"5Returns the elements, sorted by the given block.;T@S; ; i; I"Methods for Iterating;T@o;;;;[ o;;[I"#each_entry;T;[o; ;[I"2Calls the block with each successive element ;TI"%(slightly different from #each).;To;;[I"#each_with_index;T;[o; ;[I"@Calls the block with each successive element and its index.;To;;[I"#each_with_object;T;[o; ;[I"ECalls the block with each successive element and a given object.;To;;[I"#each_slice;T;[o; ;[I"#each ;TI"=which must yield successive elements of the collection. ;TI"@The method will be called by almost any \Enumerable method.;T@o; ;[I" Example:;T@o;;[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{ |element| p element } ;T;0o; ;[I" Output:;T@o;;[I"1 ;TI" [1, 2] ;TI" nil ;T;0S; ; i; I"%\Enumerable in Ruby Core Classes;To; ;[I"+Some Ruby classes include \Enumerable:;To;;;;[ o;;0;[o; ;[I" Array;To;;0;[o; ;[I"Dir;To;;0;[o; ;[I" Hash;To;;0;[o; ;[I"IO;To;;0;[o; ;[I" Range;To;;0;[o; ;[I"Set;To;;0;[o; ;[I" Struct;To; ;[I"UVirtually all methods in \Enumerable call method +#each+ in the including class:;To;;;;[o;;0;[o; ;[I"MHash#each yields the next key-value pair as a 2-element \Array.;To;;0;[o; ;[I"PStruct#each yields the next name-value pair as a 2-element \Array.;To;;0;[o; ;[I"UFor the other classes above, +#each+ yields the next object from the collection.;T@S; ; i; I"About the Examples;To; ;[I";The example code snippets for the \Enumerable methods:;To;;;;[o;;0;[o; ;[I"RAlways show the use of one or more \Array-like classes (often \Array itself).;To;;0;[o; ;[I"3Sometimes show the use of a \Hash-like class. ;TI"?For some methods, though, the usage would not make sense, ;TI"Yand so it is not shown. Example: #tally would find exactly one of each \Hash entry.;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[[;[[;[[;[I" all?;TI" enum.c;T[I" any?;T@R[I" chain;TI"enumerator.c;T[I" chunk;T@R[I"chunk_while;T@R[I" collect;T@R[I"collect_concat;T@R[I" compact;T@R[I" count;T@R[I" cycle;T@R[I" detect;T@R[I" drop;T@R[I"drop_while;T@R[I"each_cons;T@R[I"each_entry;T@R[I"each_slice;T@R[I"each_with_index;T@R[I"each_with_object;T@R[I" entries;T@R[I" filter;T@R[I"filter_map;T@R[I" find;T@R[I" find_all;T@R[I"find_index;T@R[I" first;T@R[I" flat_map;T@R[I" grep;T@R[I" grep_v;T@R[I" group_by;T@R[I" include?;T@R[I" inject;T@R[I" lazy;T@W[I"map;T@R[I"max;T@R[I" max_by;T@R[I" member?;T@R[I"min;T@R[I" min_by;T@R[I" minmax;T@R[I"minmax_by;T@R[I" none?;T@R[I" one?;T@R[I"partition;T@R[I" reduce;T@R[I" reject;T@R[I"reverse_each;T@R[I" select;T@R[I"slice_after;T@R[I"slice_before;T@R[I"slice_when;T@R[I" sort;T@R[I" sort_by;T@R[I"sum;T@R[I" take;T@R[I"take_while;T@R[I" tally;T@R[I" to_a;T@R[I" to_h;T@R[I" to_set;TI"lib/set.rb;T[I" uniq;T@R[I"zip;T@R[[U:RDoc::Context::Section[i0o;;[;0;0[I" enum.c;TI"enumerator.c;TI"lib/set.rb;T@9cRDoc::TopLevelinclude%3f-i.ri000064400000001674152373163160007266 0ustar00U:RDoc::AnyMethod[iI" include?:ETI"Enumerable#include?;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"@Returns whether for any element object == element:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"8(1..4).include?(2) # => true ;TI"9(1..4).include?(5) # => false ;TI"9(1..4).include?('2') # => false ;TI"8%w[a b c d].include?('b') # => true ;TI"9%w[a b c d].include?('2') # => false ;TI"8{foo: 0, bar: 1, baz: 2}.include?(:foo) # => true ;TI"9{foo: 0, bar: 1, baz: 2}.include?('foo') # => false ;TI"9{foo: 0, bar: 1, baz: 2}.include?(0) # => false ;T: @format0o; ; [I" [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::NormalModule00drop-i.ri000064400000001311152373163160006275 0ustar00U:RDoc::AnyMethod[iI" drop:ETI"Enumerable#drop;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I";For positive integer +n+, returns an array containing ;TI"$all but the first +n+ elements:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"r = (1..4) ;TI"r.drop(3) # => [4] ;TI"r.drop(2) # => [3, 4] ;TI"r.drop(1) # => [2, 3, 4] ;TI""r.drop(0) # => [1, 2, 3, 4] ;TI"r.drop(50) # => [] ;TI" ;TI"*h = {foo: 0, bar: 1, baz: 2, bat: 3} ;TI"*h.drop(2) # => [[:baz, 2], [:bat, 3]];T: @format0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"drop(n) -> array ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00collect-i.ri000064400000001450152373163160006762 0ustar00U:RDoc::AnyMethod[iI" collect:ETI"Enumerable#collect;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"7Returns an array of objects returned by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI";returns an array of the objects returned by the block:;T@o:RDoc::Markup::Verbatim; [I"O(0..4).map {|i| i*i } # => [0, 1, 4, 9, 16] ;TI"H{foo: 0, bar: 1, baz: 2}.map {|key, value| value*2} # => [0, 2, 4] ;T: @format0o; ; [I"1With no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"5map {|element| ... } -> array map -> enumerator ;T0[[I"map;T@ I"();T@FI"Enumerable;TcRDoc::NormalModule00lazy-i.ri000064400000002302152373163160006311 0ustar00U:RDoc::AnyMethod[iI" lazy:ETI"Enumerable#lazy;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"BReturns an Enumerator::Lazy, which redefines most Enumerable ;TI"Emethods to postpone enumeration and enumerate values only on an ;TI"as-needed basis.;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::NormalModule00tally-i.ri000064400000002356152373163160006470 0ustar00U: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::NormalModule00reverse_each-i.ri000064400000002014152373163160007765 0ustar00U:RDoc::AnyMethod[iI"reverse_each:ETI"Enumerable#reverse_each;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I" 1..4 ;TI"a # => [-4, -3, -2, -1] ;TI" ;TI" a = [] ;TI";%w[a b c d].reverse_each {|element| a.push(element) } ;TI"# => ["a", "b", "c", "d"] ;TI"!a # => ["d", "c", "b", "a"] ;TI" ;TI" a = [] ;TI"1h.reverse_each {|element| a.push(element) } ;TI"&# => {:foo=>0, :bar=>1, :baz=>2} ;TI".a # => [[:baz, 2], [:bar, 1], [:foo, 0]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"greverse_each(*args) {|element| ... } -> self reverse_each(*args) -> enumerator ;T0[I" (*args);T@"FI"Enumerable;TcRDoc::NormalModule00one%3f-i.ri000064400000003671152373163160006423 0ustar00U:RDoc::AnyMethod[iI" one?:ETI"Enumerable#one?;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"AReturns whether exactly one element meets a given criterion.;To:RDoc::Markup::BlankLineo; ; [I"$With no argument and no block, ;TI"3returns whether exactly one element is truthy:;T@o:RDoc::Markup::Verbatim; [ I"%(1..1).one? # => true ;TI"%[1, nil, false].one? # => true ;TI"&(1..4).one? # => false ;TI"%{foo: 0}.one? # => true ;TI"&{foo: 0, bar: 1}.one? # => false ;TI"&[].one? # => false ;T: @format0o; ; [I"+With argument +pattern+ and no block, ;TI"8returns whether for exactly one element +element+, ;TI""pattern === element:;T@o; ; [I"4[nil, false, 0].one?(Integer) # => true ;TI"4[nil, false, 0].one?(Numeric) # => true ;TI"5[nil, false, 0].one?(Float) # => false ;TI"4%w[bar baz bat bam].one?(/m/) # => true ;TI"5%w[bar baz bat bam].one?(/foo/) # => false ;TI"5%w[bar baz bat bam].one?('ba') # => false ;TI"5{foo: 0, bar: 1, baz: 2}.one?(Array) # => false ;TI"4{foo: 0}.one?(Array) # => true ;TI"5[].one?(Integer) # => false ;T; 0o; ; [I"JWith a block given, returns whether the block returns a truthy value ;TI"for exactly one element:;T@o; ; [ I"H(1..4).one? {|element| element < 2 } # => true ;TI"I(1..4).one? {|element| element < 1 } # => false ;TI"H{foo: 0, bar: 1, baz: 2}.one? {|key, value| value < 1 } # => true ;TI"H{foo: 0, bar: 1, baz: 2}.one? {|key, value| value < 2 } # => false ;T; 0o; ; [I"#Related: #none?, #all?, #any?.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"zone? -> true or false one?(pattern) -> true or false one? {|element| ... } -> true or false ;T0[I" (*args);T@8FI"Enumerable;TcRDoc::NormalModule00max-i.ri000064400000005237152373163160006131 0ustar00U:RDoc::AnyMethod[iI"max:ETI"Enumerable#max;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"RReturns the element with the maximum element according to a given criterion. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLineo; ; [I"AWith no argument and no block, returns the maximum element, ;TI"@using the elements' own method <=> for comparison:;T@o:RDoc::Markup::Verbatim; [ I")(1..4).max # => 4 ;TI"*(-4..-1).max # => -1 ;TI"+%w[d c b a].max # => "d" ;TI"1{foo: 0, bar: 1, baz: 2}.max # => [:foo, 0] ;TI"+[].max # => nil ;T: @format0o; ; [I"=With positive integer argument +n+ given, and no block, ;TI"Kreturns an array containing the first +n+ maximum elements that exist:;T@o; ; [ I"1(1..4).max(2) # => [4, 3] ;TI"2(-4..-1).max(2) # => [-1, -2] ;TI"5%w[d c b a].max(2) # => ["d", "c"] ;TI"A{foo: 0, bar: 1, baz: 2}.max(2) # => [[:foo, 0], [:baz, 2]] ;TI"-[].max(2) # => [] ;T; 0o; ; [I"DWith a block given, the block determines the maximum elements. ;TI"HThe block is called with two elements +a+ and +b+, and must return:;T@o:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"*A negative integer if a < b.;To;;0; [o; ; [I"Zero if a == b.;To;;0; [o; ; [I"*A positive integer if a > b.;T@o; ; [I")With a block given and no argument, ;TI" b.size } # => "xxxx" ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"Fh.max {|pair1, pair2| pair1[1] <=> pair2[1] } # => [:baz, 2] ;TI"@[].max {|a, b| a <=> b } # => nil ;T; 0o; ; [I"AWith a block given and positive integer argument +n+ given, ;TI"Lreturns an array containing the first +n+ maximum elements that exist, ;TI" as determined by the block.;T@o; ; [ I"O%w[xxx x xxxx xx].max(2) {|a, b| a.size <=> b.size } # => ["xxxx", "xxx"] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"6h.max(2) {|pair1, pair2| pair1[1] <=> pair2[1] } ;TI"!# => [[:baz, 2], [:bar, 1]] ;TI"B[].max(2) {|a, b| a <=> b } # => [] ;T; 0o; ; [I"%Related: #min, #minmax, #max_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"|max -> element max(n) -> array max {|a, b| ... } -> element max(n) {|a, b| ... } -> array ;T0[I" (*args);T@TFI"Enumerable;TcRDoc::NormalModule00collect_concat-i.ri000064400000002054152373163160010312 0ustar00U:RDoc::AnyMethod[iI"collect_concat:ETI"Enumerable#collect_concat;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"AReturns an array of flattened objects returned by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI"@returns a flattened array of objects returned by the block:;T@o:RDoc::Markup::Verbatim; [ I"Y[0, 1, 2, 3].flat_map {|element| -element } # => [0, -1, -2, -3] ;TI"e[0, 1, 2, 3].flat_map {|element| [element, -element] } # => [0, 0, 1, -1, 2, -2, 3, -3] ;TI"`[[0, 1], [2, 3]].flat_map {|e| e + [100] } # => [0, 1, 100, 2, 3, 100] ;TI"e{foo: 0, bar: 1, baz: 2}.flat_map {|key, value| [key, value] } # => [:foo, 0, :bar, 1, :baz, 2] ;T: @format0o; ; [I"1With no block given, returns an \Enumerator.;T@o; ; [I"Alias: #collect_concat.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I"();T@FI"Enumerable;TcRDoc::NormalModule0[@"FI" flat_map;Tselect-i.ri000064400000001523152373163160006615 0ustar00U:RDoc::AnyMethod[iI" select:ETI"Enumerable#select;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;Teach_cons-i.ri000064400000001570152373163160007262 0ustar00U:RDoc::AnyMethod[iI"each_cons:ETI"Enumerable#each_cons;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"LCalls the block with each successive overlapped +n+-tuple of elements; ;TI"returns +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I" a = [] ;TI"6(1..5).each_cons(3) {|element| a.push(element) } ;TI".a # => [[1, 2, 3], [2, 3, 4], [3, 4, 5]] ;TI" ;TI" a = [] ;TI"+h = {foo: 0, bar: 1, baz: 2, bam: 3} ;TI"1h.each_cons(2) {|element| a.push(element) } ;TI"Ua # => [[[:foo, 0], [:bar, 1]], [[:bar, 1], [:baz, 2]], [[:baz, 2], [:bam, 3]]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Geach_cons(n) { ... } -> self each_cons(n) -> enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00sum-i.ri000064400000002711152373163160006142 0ustar00U: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::NormalModule00count-i.ri000064400000002201152373163160006460 0ustar00U:RDoc::AnyMethod[iI" count:ETI"Enumerable#count;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"VReturns the count of elements, based on an argument or block criterion, if given.;To:RDoc::Markup::BlankLineo; ; [I"IWith no argument and no block given, returns the number of elements:;T@o:RDoc::Markup::Verbatim; [I"+[0, 1, 2].count # => 3 ;TI"+{foo: 0, bar: 1, baz: 2}.count # => 3 ;T: @format0o; ; [I"#With argument +object+ given, ;TI"Ereturns the number of elements that are == to +object+:;T@o; ; [I",[0, 1, 2, 1].count(1) # => 2 ;T; 0o; ; [I";With a block given, calls the block with each element ;TI"Sand returns the number of elements for which the block returns a truthy value:;T@o; ; [I"D[0, 1, 2, 3].count {|element| element < 2} # => 2 ;TI"C{foo: 0, bar: 1, baz: 2}.count {|key, value| value < 2} # => 2;T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Qcount -> integer count(object) -> integer count {|element| ... } -> integer ;T0[I" (p1);T@%FI"Enumerable;TcRDoc::NormalModule00all%3f-i.ri000064400000003563152373163160006412 0ustar00U:RDoc::AnyMethod[iI" all?:ETI"Enumerable#all?;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I";Returns whether every element meets a given criterion.;To:RDoc::Markup::BlankLineo; ; [I"$With no argument and no block, ;TI"-returns whether every element is truthy:;T@o:RDoc::Markup::Verbatim; [ I"%(1..4).all? # => true ;TI"%%w[a b c d].all? # => true ;TI"&[1, 2, nil].all? # => false ;TI"&['a','b', false].all? # => false ;TI"%[].all? # => true ;T: @format0o; ; [I"+With argument +pattern+ and no block, ;TI"1returns whether for each element +element+, ;TI""pattern === element:;T@o; ; [I"4(1..4).all?(Integer) # => true ;TI"4(1..4).all?(Numeric) # => true ;TI"5(1..4).all?(Float) # => false ;TI"4%w[bar baz bat bam].all?(/ba/) # => true ;TI"5%w[bar baz bat bam].all?(/bar/) # => false ;TI"5%w[bar baz bat bam].all?('ba') # => false ;TI"4{foo: 0, bar: 1, baz: 2}.all?(Array) # => true ;TI"5{foo: 0, bar: 1, baz: 2}.all?(Hash) # => false ;TI"4[].all?(Integer) # => true ;T; 0o; ; [I"JWith a block given, returns whether the block returns a truthy value ;TI"for every element:;T@o; ; [ I"G(1..4).all? {|element| element < 5 } # => true ;TI"H(1..4).all? {|element| element < 4 } # => false ;TI"G{foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 3 } # => true ;TI"H{foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 2 } # => false ;T; 0o; ; [I""Related: #any?, #none? #one?.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"zall? -> true or false all?(pattern) -> true or false all? {|element| ... } -> true or false ;T0[I" (*args);T@7FI"Enumerable;TcRDoc::NormalModule00chunk_while-i.ri000064400000004411152373163160007635 0ustar00U: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::NormalModule00uniq-i.ri000064400000001732152373163160006314 0ustar00U: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::NormalModule00min-i.ri000064400000005225152373163160006124 0ustar00U:RDoc::AnyMethod[iI"min:ETI"Enumerable#min;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"RReturns the element with the minimum element according to a given criterion. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLineo; ; [I"AWith no argument and no block, returns the minimum element, ;TI"@using the elements' own method <=> for comparison:;T@o:RDoc::Markup::Verbatim; [ I")(1..4).min # => 1 ;TI"*(-4..-1).min # => -4 ;TI"+%w[d c b a].min # => "a" ;TI"1{foo: 0, bar: 1, baz: 2}.min # => [:bar, 1] ;TI"+[].min # => nil ;T: @format0o; ; [I"=With positive integer argument +n+ given, and no block, ;TI"Kreturns an array containing the first +n+ minimum elements that exist:;T@o; ; [ I"1(1..4).min(2) # => [1, 2] ;TI"3(-4..-1).min(2) # => [-4, -3] ;TI"5%w[d c b a].min(2) # => ["a", "b"] ;TI"A{foo: 0, bar: 1, baz: 2}.min(2) # => [[:bar, 1], [:baz, 2]] ;TI"-[].min(2) # => [] ;T; 0o; ; [I"DWith a block given, the block determines the minimum elements. ;TI"HThe block is called with two elements +a+ and +b+, and must return:;T@o:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"*A negative integer if a < b.;To;;0; [o; ; [I"Zero if a == b.;To;;0; [o; ; [I"*A positive integer if a > b.;T@o; ; [I")With a block given and no argument, ;TI" b.size } # => "x" ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"Bh.min {|pair1, pair2| pair1[1] <=> pair2[1] } # => [:foo, 0] ;TI"@[].min {|a, b| a <=> b } # => nil ;T; 0o; ; [I"AWith a block given and positive integer argument +n+ given, ;TI"Lreturns an array containing the first +n+ minimum elements that exist, ;TI" as determined by the block.;T@o; ; [ I"K%w[xxx x xxxx xx].min(2) {|a, b| a.size <=> b.size } # => ["x", "xx"] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"6h.min(2) {|pair1, pair2| pair1[1] <=> pair2[1] } ;TI"!# => [[:foo, 0], [:bar, 1]] ;TI"B[].min(2) {|a, b| a <=> b } # => [] ;T; 0o; ; [I"%Related: #min_by, #minmax, #max.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"|min -> element min(n) -> array min {|a, b| ... } -> element min(n) {|a, b| ... } -> array ;T0[I" (*args);T@TFI"Enumerable;TcRDoc::NormalModule00flat_map-i.ri000064400000002146152373163160007123 0ustar00U:RDoc::AnyMethod[iI" flat_map:ETI"Enumerable#flat_map;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"AReturns an array of flattened objects returned by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI"@returns a flattened array of objects returned by the block:;T@o:RDoc::Markup::Verbatim; [ I"Y[0, 1, 2, 3].flat_map {|element| -element } # => [0, -1, -2, -3] ;TI"e[0, 1, 2, 3].flat_map {|element| [element, -element] } # => [0, 0, 1, -1, 2, -2, 3, -3] ;TI"`[[0, 1], [2, 3]].flat_map {|e| e + [100] } # => [0, 1, 100, 2, 3, 100] ;TI"e{foo: 0, bar: 1, baz: 2}.flat_map {|key, value| [key, value] } # => [:foo, 0, :bar, 1, :baz, 2] ;T: @format0o; ; [I"1With no block given, returns an \Enumerator.;T@o; ; [I"Alias: #collect_concat.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"?flat_map {|element| ... } -> array flat_map -> enumerator ;T0[[I"collect_concat;T@ I"();T@FI"Enumerable;TcRDoc::NormalModule00find_index-i.ri000064400000002205152373163160007443 0ustar00U:RDoc::AnyMethod[iI"find_index:ETI"Enumerable#find_index;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"NReturns the index of the first element that meets a specified criterion, ;TI"*or +nil+ if no such element is found.;To:RDoc::Markup::BlankLineo; ; [I"#With argument +object+ given, ;TI"Ireturns the index of the first element that is == +object+:;T@o:RDoc::Markup::Verbatim; [I"1['a', 'b', 'c', 'b'].find_index('b') # => 1 ;T: @format0o; ; [I"CWith a block given, calls the block with successive elements; ;TI"Jreturns the first element for which the block returns a truthy value:;T@o; ; [I"R['a', 'b', 'c', 'b'].find_index {|element| element.start_with?('b') } # => 1 ;TI"R{foo: 0, bar: 1, baz: 2}.find_index {|key, value| value > 1 } # => 2 ;T; 0o; ; [I"AWith no argument and no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"qfind_index(object) -> integer or nil find_index {|element| ... } -> integer or nil find_index -> enumerator ;T0[I" (p1);T@"FI"Enumerable;TcRDoc::NormalModule00drop_while-i.ri000064400000001457152373163160007500 0ustar00U:RDoc::AnyMethod[iI"drop_while:ETI"Enumerable#drop_while;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"CCalls the block with successive elements as long as the block ;TI"returns a truthy value; ;TI"7returns an array of all elements after that point:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"/(1..4).drop_while{|i| i < 3 } # => [3, 4] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"Ca = h.drop_while{|element| key, value = *element; value < 2 } ;TI"a # => [[:baz, 2]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Tdrop_while {|element| ... } -> array drop_while -> enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00map-i.ri000064400000001356152373163160006117 0ustar00U:RDoc::AnyMethod[iI"map:ETI"Enumerable#map;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"7Returns an array of objects returned by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI";returns an array of the objects returned by the block:;T@o:RDoc::Markup::Verbatim; [I"O(0..4).map {|i| i*i } # => [0, 1, 4, 9, 16] ;TI"H{foo: 0, bar: 1, baz: 2}.map {|key, value| value*2} # => [0, 2, 4] ;T: @format0o; ; [I"1With no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I"();T@FI"Enumerable;TcRDoc::NormalModule0[@FI" collect;Tcompact-i.ri000064400000001016152373163160006761 0ustar00U: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::NormalModule00each_slice-i.ri000064400000001571152373163160007420 0ustar00U:RDoc::AnyMethod[iI"each_slice:ETI"Enumerable#each_slice;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"JCalls the block with each successive disjoint +n+-tuple of elements; ;TI"returns +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I" a = [] ;TI"4(1..10).each_slice(3) {|tuple| a.push(tuple) } ;TI"4a # => [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] ;TI" ;TI" a = [] ;TI"2h = {foo: 0, bar: 1, baz: 2, bat: 3, bam: 4} ;TI".h.each_slice(2) {|tuple| a.push(tuple) } ;TI"Ja # => [[[:foo, 0], [:bar, 1]], [[:baz, 2], [:bat, 3]], [[:bam, 4]]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Keach_slice(n) { ... } -> self each_slice(n) -> enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00reject-i.ri000064400000001576152373163160006622 0ustar00U:RDoc::AnyMethod[iI" reject:ETI"Enumerable#reject;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"7Returns an array of objects rejected by the block.;To:RDoc::Markup::BlankLineo; ; [I"CWith a block given, calls the block with successive elements; ;TI"Ureturns an array of those elements for which the block returns +nil+ or +false+:;T@o:RDoc::Markup::Verbatim; [I"\(0..9).reject {|i| i * 2 if i.even? } # => [1, 3, 5, 7, 9] ;TI"_{foo: 0, bar: 1, baz: 2}.reject {|key, value| key if value.odd? } # => {:foo=>0, :baz=>2} ;T: @format0o; ; [I"1When no block given, returns an \Enumerator.;T@o; ; [I"Related: #select.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I";reject {|element| ... } -> array reject -> enumerator ;T0[I"();T@FI"Enumerable;TcRDoc::NormalModule00member%3f-i.ri000064400000001743152373163160007107 0ustar00U:RDoc::AnyMethod[iI" member?:ETI"Enumerable#member?;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"@Returns whether for any element object == element:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"8(1..4).include?(2) # => true ;TI"9(1..4).include?(5) # => false ;TI"9(1..4).include?('2') # => false ;TI"8%w[a b c d].include?('b') # => true ;TI"9%w[a b c d].include?('2') # => false ;TI"8{foo: 0, bar: 1, baz: 2}.include?(:foo) # => true ;TI"9{foo: 0, bar: 1, baz: 2}.include?('foo') # => false ;TI"9{foo: 0, bar: 1, baz: 2}.include?(0) # => false ;T: @format0o; ; [I" true or false ;T0[[I" include?;T@ I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00detect-i.ri000064400000002101152373163160006577 0ustar00U:RDoc::AnyMethod[iI" detect:ETI"Enumerable#detect;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JReturns the first element for which the block returns a truthy value.;To:RDoc::Markup::BlankLineo; ; [I"UWith a block given, calls the block with successive elements of the collection; ;TI"Jreturns the first element for which the block returns a truthy value:;T@o:RDoc::Markup::Verbatim; [I"?(0..9).find {|element| element > 2} # => 3 ;T: @format0o; ; [I"TIf no such element is found, calls +if_none_proc+ and returns its return value.;T@o; ; [I"C(0..9).find(proc {false}) {|element| element > 12} # => false ;TI"b{foo: 0, bar: 1, baz: 2}.find {|key, value| key.start_with?('b') } # => [:bar, 1] ;TI"[{foo: 0, bar: 1, baz: 2}.find(proc {[]}) {|key, value| key.start_with?('c') } # => [] ;T; 0o; ; [I"1With no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I" (*args);T@!FI"Enumerable;TcRDoc::NormalModule0[@$FI" find;Teach_entry-i.ri000064400000002243152373163160007457 0ustar00U:RDoc::AnyMethod[iI"each_entry:ETI"Enumerable#each_entry;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I".Calls the given block with each element, ;TI"Gconverting multiple values from yield to an array; returns +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I" a = [] ;TI">(1..4).each_entry {|element| a.push(element) } # => 1..4 ;TI"a # => [1, 2, 3, 4] ;TI" ;TI" a = [] ;TI"!h = {foo: 0, bar: 1, baz:2} ;TI"/h.each_entry {|element| a.push(element) } ;TI"&# => {:foo=>0, :bar=>1, :baz=>2} ;TI".a # => [[:foo, 0], [:bar, 1], [:baz, 2]] ;TI" ;TI"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 {|yielded| p yielded } ;T: @format0o; ; [I" Output:;T@o; ; [I"1 ;TI" [1, 2] ;TI" nil ;T; 0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"aeach_entry(*args) {|element| ... } -> self each_entry(*args) -> enumerator ;T0[I" (*args);T@0FI"Enumerable;TcRDoc::NormalModule00to_set-i.ri000064400000000635152373163160006636 0ustar00U:RDoc::AnyMethod[iI" to_set:ETI"Enumerable#to_set;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"yMakes a set from the enumerable object with given arguments. Needs 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::NormalModule00each_with_index-i.ri000064400000002163152373163160010461 0ustar00U:RDoc::AnyMethod[iI"each_with_index:ETI"Enumerable#each_with_index;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"JWith a block given, calls the block with each element and its index; ;TI"returns +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I" h = {} ;TI"E(1..4).each_with_index {|element, i| h[element] = i } # => 1..4 ;TI"%h # => {1=>0, 2=>1, 3=>2, 4=>3} ;TI" ;TI" h = {} ;TI"@%w[a b c d].each_with_index {|element, i| h[element] = i } ;TI"# => ["a", "b", "c", "d"] ;TI"-h # => {"a"=>0, "b"=>1, "c"=>2, "d"=>3} ;TI" ;TI" a = [] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI" {:foo=>0, :bar=>1, :baz=>2} ;TI"=a # => [[0, [:foo, 0]], [1, [:bar, 1]], [2, [:baz, 2]]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"ueach_with_index(*args) {|element, i| ..... } -> self each_with_index(*args) -> enumerator ;T0[I" (*args);T@#FI"Enumerable;TcRDoc::NormalModule00to_h-i.ri000064400000001754152373163160006275 0ustar00U:RDoc::AnyMethod[iI" to_h:ETI"Enumerable#to_h;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"/When +self+ consists of 2-element arrays, ;TI"@returns a hash each of whose entries is the key-value pair ;TI"%formed from one of those arrays:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"M[[:foo, 0], [:bar, 1], [:baz, 2]].to_h # => {:foo=>0, :bar=>1, :baz=>2} ;T: @format0o; ; [I"MWhen a block is given, the block is called with each element of +self+; ;TI"Nthe block should return a 2-element array which becomes a key-value pair ;TI"in the returned hash:;T@o; ; [I"A(0..3).to_h {|i| [i, i ** 2]} # => {0=>0, 1=>1, 2=>4, 3=>9} ;T; 0o; ; [I"KRaises an exception if an element of +self+ is not a 2-element array, ;TI"and a block is not passed.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"1to_h -> hash to_h {|element| ... } -> hash ;T0[I" (*args);T@ FI"Enumerable;TcRDoc::NormalModule00cycle-i.ri000064400000002312152373163160006432 0ustar00U:RDoc::AnyMethod[iI" cycle:ETI"Enumerable#cycle;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"AWhen called with positive integer argument +n+ and a block, ;TI" nil ;TI"1a # => [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] ;TI" a = [] ;TI"6('a'..'d').cycle(2) {|element| a.push(element) } ;TI"5a # => ["a", "b", "c", "d", "a", "b", "c", "d"] ;TI" a = [] ;TI"D{foo: 0, bar: 1, baz: 2}.cycle(2) {|element| a.push(element) } ;TI"Oa # => [[:foo, 0], [:bar, 1], [:baz, 2], [:foo, 0], [:bar, 1], [:baz, 2]] ;T: @format0o; ; [I";If count is zero or negative, does not call the block.;T@o; ; [I"?When called with a block and +n+ is +nil+, cycles forever.;T@o; ; [I"3When no block is given, returns an Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Zcycle(n = nil) {|element| ...} -> nil cycle(n = nil) -> enumerator ;T0[I" (*args);T@%FI"Enumerable;TcRDoc::NormalModule00find-i.ri000064400000002247152373163160006262 0ustar00U:RDoc::AnyMethod[iI" find:ETI"Enumerable#find;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JReturns the first element for which the block returns a truthy value.;To:RDoc::Markup::BlankLineo; ; [I"UWith a block given, calls the block with successive elements of the collection; ;TI"Jreturns the first element for which the block returns a truthy value:;T@o:RDoc::Markup::Verbatim; [I"?(0..9).find {|element| element > 2} # => 3 ;T: @format0o; ; [I"TIf no such element is found, calls +if_none_proc+ and returns its return value.;T@o; ; [I"C(0..9).find(proc {false}) {|element| element > 12} # => false ;TI"b{foo: 0, bar: 1, baz: 2}.find {|key, value| key.start_with?('b') } # => [:bar, 1] ;TI"[{foo: 0, bar: 1, baz: 2}.find(proc {[]}) {|key, value| key.start_with?('c') } # => [] ;T; 0o; ; [I"1With no block given, returns an \Enumerator.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"gfind(if_none_proc = nil) {|element| ... } -> object or nil find(if_none_proc = nil) -> enumerator ;T0[[I" detect;T@ I" (*args);T@!FI"Enumerable;TcRDoc::NormalModule00minmax-i.ri000064400000002733152373163160006633 0ustar00U:RDoc::AnyMethod[iI" minmax:ETI"Enumerable#minmax;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"KReturns a 2-element array containing the minimum and maximum elements ;TI"%according to a given criterion. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLineo; ; [I"NWith no argument and no block, returns the minimum and maximum elements, ;TI"@using the elements' own method <=> for comparison:;T@o:RDoc::Markup::Verbatim; [ I"1(1..4).minmax # => [1, 4] ;TI"3(-4..-1).minmax # => [-4, -1] ;TI"5%w[d c b a].minmax # => ["a", "d"] ;TI"A{foo: 0, bar: 1, baz: 2}.minmax # => [[:bar, 1], [:foo, 0]] ;TI"5[].minmax # => [nil, nil] ;T: @format0o; ; [I"BWith a block given, returns the minimum and maximum elements ;TI" as determined by the block:;T@o; ; [ I"M%w[xxx x xxxx xx].minmax {|a, b| a.size <=> b.size } # => ["x", "xxxx"] ;TI""h = {foo: 0, bar: 1, baz: 2} ;TI"6h.minmax {|pair1, pair2| pair1[1] <=> pair2[1] } ;TI"!# => [[:foo, 0], [:baz, 2]] ;TI"J[].minmax {|a, b| a <=> b } # => [nil, nil] ;T; 0o; ; [I"%Related: #min, #max, #minmax_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"[minmax -> [minimum, maximum] minmax {|a, b| ... } -> [minimum, maximum] ;T0[I"();T@*FI"Enumerable;TcRDoc::NormalModule00slice_when-i.ri000064400000005542152373163160007463 0ustar00U: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::NormalModule00entries-i.ri000064400000000776152373163160007020 0ustar00U:RDoc::AnyMethod[iI" entries:ETI"Enumerable#entries;TF: privateo:RDoc::Markup::Document: @parts[ o:RDoc::Markup::Paragraph; [I"5Returns an array containing the items in +self+:;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"&(0..4).to_a # => [0, 1, 2, 3, 4] ;T: @format0o; ; [I"8Enumerable#entries is an alias for Enumerable#to_a.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below000[I" (*args);T@FI"Enumerable;TcRDoc::NormalModule0[@FI" to_a;Tchain-i.ri000064400000001025152373163160006415 0ustar00U: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::NormalModule00max_by-i.ri000064400000003055152373163160006617 0ustar00U:RDoc::AnyMethod[iI" max_by:ETI"Enumerable#max_by;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"IReturns the elements for which the block returns the maximum values.;To:RDoc::Markup::BlankLineo; ; [I")With a block given and no argument, ;TI"Greturns the element for which the block returns the maximum value:;T@o:RDoc::Markup::Verbatim; [ I"C(1..4).max_by {|element| -element } # => 1 ;TI"E%w[a b c d].max_by {|element| -element.ord } # => "a" ;TI"K{foo: 0, bar: 1, baz: 2}.max_by {|key, value| -value } # => [:foo, 0] ;TI"E[].max_by {|element| -element } # => nil ;T: @format0o; ; [I"AWith a block given and positive integer argument +n+ given, ;TI"2returns an array containing the +n+ elements ;TI"0for which the block returns maximum values:;T@o; ; [ I",(1..4).max_by(2) {|element| -element } ;TI"# => [1, 2] ;TI"5%w[a b c d].max_by(2) {|element| -element.ord } ;TI"# => ["a", "b"] ;TI"?{foo: 0, bar: 1, baz: 2}.max_by(2) {|key, value| -value } ;TI"!# => [[:foo, 0], [:bar, 1]] ;TI"([].max_by(2) {|element| -element } ;TI" # => [] ;T; 0o; ; [I"0Returns an Enumerator if no block is given.;T@o; ; [I"%Related: #max, #minmax, #min_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"max_by {|element| ... } -> element max_by(n) {|element| ... } -> array max_by -> enumerator max_by(n) -> enumerator ;T0[I" (*args);T@.FI"Enumerable;TcRDoc::NormalModule00grep_v-i.ri000064400000002236152373163160006622 0ustar00U: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::NormalModule00sort_by-i.ri000064400000006617152373163160007030 0ustar00U:RDoc::AnyMethod[iI" sort_by:ETI"Enumerable#sort_by;TF: privateo:RDoc::Markup::Document: @parts[!o:RDoc::Markup::Paragraph; [I"AWith a block given, returns an array of elements of +self+, ;TI"Ksorted according to the value returned by the block for each element. ;TI"IThe ordering of equal elements is indeterminate and may be unstable.;To:RDoc::Markup::BlankLineo; ; [I"Examples:;T@o:RDoc::Markup::Verbatim; [ I"a = %w[xx xxx x xxxx] ;TI"Da.sort_by {|s| s.size } # => ["x", "xx", "xxx", "xxxx"] ;TI"Da.sort_by {|s| -s.size } # => ["xxxx", "xxx", "xx", "x"] ;TI""h = {foo: 2, bar: 1, baz: 0} ;TI"Kh.sort_by{|key, value| value } # => [[:baz, 0], [:bar, 1], [:foo, 2]] ;TI"Kh.sort_by{|key, value| key } # => [[:bar, 1], [:baz, 0], [:foo, 2]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T@o; ; [ I"BThe current implementation of #sort_by generates an array of ;TI"Ftuples containing the original collection element and the mapped ;TI"Fvalue. This makes #sort_by fairly expensive when the keysets are ;TI" 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"9This sort is inefficient: it generates two new File ;TI"Hobjects during every comparison. A slightly better technique is to ;TI"=use 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"@This still generates many unnecessary Time objects. A more ;TI"Gefficient technique is to cache the sort keys (modification times ;TI"Hin this case) before the sort. Perl users often call this approach ;TI"Da Schwartzian transform, after Randal Schwartz. We construct a ;TI"Dtemporary array, where each element is an array containing our ;TI"Dsort key along with the filename. We sort this array, and then ;TI"*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"3This is exactly what #sort_by does internally.;T@o; ; [I"3sorted = Dir["*"].sort_by { |f| test(?M, f) } ;TI"2sorted #=> ["mon", "tues", "wed", "thurs"] ;T; 0o; ; [I"KTo produce the reverse of a specific order, the following can be used:;T@o; ; [I"!ary.sort_by { ... }.reverse!;T; 0: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Nsort_by {|element| ... } -> array sort_by -> enumerator ;T0[I"();T@jFI"Enumerable;TcRDoc::NormalModule00any%3f-i.ri000064400000003502152373163160006422 0ustar00U:RDoc::AnyMethod[iI" any?:ETI"Enumerable#any?;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"9Returns whether any element meets a given criterion.;To:RDoc::Markup::BlankLineo; ; [I"$With no argument and no block, ;TI"+returns whether any element is truthy:;T@o:RDoc::Markup::Verbatim; [ I"$(1..4).any? # => true ;TI"$%w[a b c d].any? # => true ;TI"$[1, false, nil].any? # => true ;TI"%[].any? # => false ;T: @format0o; ; [I"+With argument +pattern+ and no block, ;TI"0returns whether for any element +element+, ;TI""pattern === element:;T@o; ; [I"4[nil, false, 0].any?(Integer) # => true ;TI"4[nil, false, 0].any?(Numeric) # => true ;TI"5[nil, false, 0].any?(Float) # => false ;TI"4%w[bar baz bat bam].any?(/m/) # => true ;TI"5%w[bar baz bat bam].any?(/foo/) # => false ;TI"5%w[bar baz bat bam].any?('ba') # => false ;TI"4{foo: 0, bar: 1, baz: 2}.any?(Array) # => true ;TI"5{foo: 0, bar: 1, baz: 2}.any?(Hash) # => false ;TI"5[].any?(Integer) # => false ;T; 0o; ; [I"JWith a block given, returns whether the block returns a truthy value ;TI"for any element:;T@o; ; [ I"G(1..4).any? {|element| element < 2 } # => true ;TI"H(1..4).any? {|element| element < 1 } # => false ;TI"G{foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 1 } # => true ;TI"H{foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 0 } # => false ;T; 0o; ; [I"#Related: #all?, #none?, #one?.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"zany? -> true or false any?(pattern) -> true or false any? {|element| ... } -> true or false ;T0[I" (*args);T@6FI"Enumerable;TcRDoc::NormalModule00slice_before-i.ri000064400000012533152373163160007762 0ustar00U:RDoc::AnyMethod[iI"slice_before:ETI"Enumerable#slice_before;TF: privateo:RDoc::Markup::Document: @parts["o:RDoc::Markup::Paragraph; [ I"JWith argument +pattern+, returns an enumerator that uses the pattern ;TI"3to partition elements into arrays ("slices"). ;TI"CAn element begins a new slice if element === pattern ;TI"%(or if it is the first element).;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"1a = %w[foo bar fop for baz fob fog bam foy] ;TI"6e = a.slice_before(/ba/) # => # ;TI"e.each {|array| p array } ;T: @format0o; ; [I" Output:;T@o; ; [ I" ["foo"] ;TI"["bar", "fop", "for"] ;TI"["baz", "fob", "fog"] ;TI"["bam", "foy"] ;T; 0o; ; [ I"=With a block, returns an enumerator that uses the block ;TI"(to partition elements into arrays. ;TI"IAn element begins a new slice if its block return is a truthy value ;TI"%(or if it is the first element):;T@o; ; [I"He = (1..20).slice_before {|i| i % 4 == 2 } # => # ;TI"e.each {|array| p array } ;T; 0o; ; [I" Output:;T@o; ; [ I" [1] ;TI"[2, 3, 4, 5] ;TI"[6, 7, 8, 9] ;TI"[10, 11, 12, 13] ;TI"[14, 15, 16, 17] ;TI"[18, 19, 20] ;T; 0o; ; [I"BOther methods of the Enumerator class and Enumerable module, ;TI"2such as +to_a+, +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"5as follows (see +chunk_while+ for a better way):;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"6However local variables should be used carefully ;TI";if the result enumerator is enumerated twice or more. ;TI"EThe local variables should be initialized for each enumeration. ;TI")Enumerator.new can be used to do it.;T@o; ; [,I"D# Word wrapping. This assumes all characters have same width. ;TI"#def wordwrap(words, maxwidth) ;TI" Enumerator.new {|y| ;TI"2 # cols is initialized in Enumerator.new. ;TI" cols = 0 ;TI"" words.slice_before { |w| ;TI"" cols += 1 if cols != 0 ;TI" cols += w.length ;TI" if maxwidth < cols ;TI" cols = w.length ;TI" true ;TI" else ;TI" false ;TI" end ;TI"# }.each {|ws| y.yield ws } ;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(" ") } # first enumeration. ;TI"puts "-"*10 ;TI"cenum.each { |ws| puts ws.join(" ") } # second enumeration generates same result as the first. ;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"# ---------- ;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" emp = true ;TI" f.slice_before { |line| ;TI" prevemp = emp ;TI" 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"Yslice_before(pattern) -> enumerator slice_before {|array| ... } -> enumerator ;T0[I" (p1);T@FI"Enumerable;TcRDoc::NormalModule00partition-i.ri000064400000002406152373163160007350 0ustar00U:RDoc::AnyMethod[iI"partition:ETI"Enumerable#partition;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"8With a block given, returns an array of two arrays:;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0; [o; ; [I"PThe first having those elements for which the block returns a truthy value.;To;;0; [o; ; [I")The other having all other elements.;T@o; ; [I"Examples:;T@o:RDoc::Markup::Verbatim; [I")p = (1..4).partition {|i| i.even? } ;TI"p # => [[2, 4], [1, 3]] ;TI"-p = ('a'..'d').partition {|c| c < 'c' } ;TI"%p # => [["a", "b"], ["c", "d"]] ;TI"*h = {foo: 0, bar: 1, baz: 2, bat: 3} ;TI":p = h.partition {|key, value| key.start_with?('b') } ;TI"=p # => [[[:bar, 1], [:baz, 2], [:bat, 3]], [[:foo, 0]]] ;TI"/p = h.partition {|key, value| value < 2 } ;TI"=p # => [[[:foo, 0], [:bar, 1]], [[:baz, 2], [:bat, 3]]] ;T: @format0o; ; [I"0With no block given, returns an Enumerator.;T@o; ; [I""Related: Enumerable#group_by.;T: @fileI" enum.c;T:0@omit_headings_from_table_of_contents_below0I"Upartition {|element| ... } -> [true_array, false_array] partition -> enumerator ;T0[I"();T@/FI"Enumerable;TcRDoc::NormalModule00