Method: Array#unzip
- Defined in:
- lib/imw/utils/extensions/array.rb
#unzip ⇒ Object
‘Un’-zip()s an array. Returns an array of arrays: the first array has the first element of each member, the second array has the second element of each member, and so on. Returns as many arrays as the first element in self and inserts a nil where the member array wasn’t long enough.
foo, bar = foo.zip(bar).unzip should leave foo and bar with the same values if foo and bar have the same length.
Will fail on a not-array-of-arrays.
24 25 26 27 28 29 30 31 32 |
# File 'lib/imw/utils/extensions/array.rb', line 24 def unzip() # An array of empty arrays, one for each vertical slot vslices = self[0].map{ Array.new } self.each do |hslice| # push the elements of each array onto its slice. vslices.zip(hslice).map{|vslice,h_el| vslice << h_el } end vslices end |