kernel/common/array.rb
# Treats all elements as being Arrays of equal lengths and
# transposes their rows and columns so that the first contained
# Array in the result includes the first elements of all the
# Arrays and so on.
Treats all elements as being Arrays of equal lengths and
transposes their rows and columns so that the first contained
Array in the result includes the first elements of all the
Arrays and so on.
Treats all elements as being Arrays of equal lengths and transposes their rows and columns so that the first contained Array in the result includes the first elements of all the Arrays and so on .
def transpose()
    return [] if empty?
    out, max = [], nil
    each { |ary|
      ary = Type.coerce_to ary, Array, :to_ary
      max ||= ary.size
      raise IndexError, "All arrays must be same length" if ary.size != max
      ary.size.times { |i| (out[i] ||= []) << ary.at(i) }
    }
    out
  end
def transpose ( ) return [ ] if empty? out , max = [ ] , nil each { | ary | ary = Type . coerce_to ary , Array , :to_ary max ||= ary . size raise IndexError , "All arrays must be same length" if ary . size != max ary . size . times { | i | ( out [ i ] ||= [ ] ) << ary . at ( i ) } } out end
Treats all elements as being Arrays of equal lengths and
transposes their rows and columns so that the first contained
Array in the result includes the first elements of all the
Arrays and so on.
Treats all elements as being Arrays of equal lengths and transposes their rows and columns so that the first contained Array in the result includes the first elements of all the Arrays and so on .
# Catches too-large as well as too-small (for which #fetch would suffice)