D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
zip-i.ri
back
Copy
U:RDoc::AnyMethod[iI"zip:ETI"Array#zip;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"QWith no block given, combines +self+ with the collection of +other_arrays+; ;TI"'returns a new array of sub-arrays:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"0[0, 1].zip(['zero', 'one'], [:zero, :one]) ;TI"1# => [[0, "zero", :zero], [1, "one", :one]] ;T:@format0o; ; [I"Returned:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"3The outer array is of size <tt>self.size</tt>.;To;;0; [o; ; [I">Each sub-array is of size <tt>other_arrays.size + 1</tt>.;To;;0; [o; ; [I"-The _nth_ sub-array contains (in order):;T@o;;;;[o;;0; [o; ; [I"!The _nth_ element of +self+.;To;;0; [o; ; [I"AThe _nth_ element of each of the other arrays, as available.;T@o; ; [I" Example:;T@o;; [ I"a = [0, 1] ;TI"4zipped = a.zip(['zero', 'one'], [:zero, :one]) ;TI"1# => [[0, "zero", :zero], [1, "one", :one]] ;TI"0zipped.size # => 2 # Same size as a. ;TI"=zipped.first.size # => 3 # Size of other arrays plus 1. ;T; 0o; ; [I"<When the other arrays are all the same size as +self+, ;TI"_the returned sub-arrays are a rearrangement containing exactly elements of all the arrays ;TI"8(including +self+), with no omissions or additions:;T@o;; [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" pp d ;TI" # => ;TI"[[:a0, :b0, :c0], ;TI" [:a1, :b1, :c1], ;TI" [:a2, :b2, :c2], ;TI" [:a3, :b3, :c3]] ;T; 0o; ; [I":When one of the other arrays is smaller than +self+, ;TI":pads the corresponding sub-array with +nil+ elements:;T@o;; [I"a = [:a0, :a1, :a2, :a3] ;TI"b = [:b0, :b1, :b2] ;TI"c = [:c0, :c1] ;TI"d = a.zip(b, c) ;TI" pp d ;TI" # => ;TI"[[:a0, :b0, :c0], ;TI" [:a1, :b1, :c1], ;TI" [:a2, :b2, nil], ;TI" [:a3, nil, nil]] ;T; 0o; ; [I"9When one of the other arrays is larger than +self+, ;TI"%_ignores_ its trailing elements:;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" pp d ;TI" # => ;TI"[[:a0, :b0, :c0], ;TI" [:a1, :b1, :c1], ;TI" [:a2, :b2, :c2], ;TI" [:a3, :b3, :c3]] ;T; 0o; ; [I"HWith a block given, calls the block with each of the other arrays; ;TI"returns +nil+:;T@o;; [I"d = [] ;TI"a = [:a0, :a1, :a2, :a3] ;TI"b = [:b0, :b1, :b2, :b3] ;TI"c = [:c0, :c1, :c2, :c3] ;TI"Ca.zip(b, c) {|sub_array| d.push(sub_array.reverse) } # => nil ;TI" pp d ;TI" # => ;TI"[[:c0, :b0, :a0], ;TI" [:c1, :b1, :a1], ;TI" [:c2, :b2, :a2], ;TI" [:c3, :b3, :a3]] ;T; 0o; ; [I"FFor an *object* in *other_arrays* that is not actually an array, ;TI"Hforms the the "other array" as <tt>object.to_ary</tt>, if defined, ;TI"/or as <tt>object.each.to_a</tt> otherwise.;T@o; ; [I"RRelated: see {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"Rzip(*other_arrays) -> new_array zip(*other_arrays) {|sub_array| ... } -> nil ;T0[ I"(*args);T@�FI" Array;TcRDoc::NormalClass00