#transpose
Assumes that self is an array of arrays and transposes the rows and columns.
#zip
assumes self
can be any Enumerable
object.
More differences are here
a = [12,11,21]
b = [1,2]
[a,b].transpose # transpose': element size differs (2 should be 3) (IndexError)
a.zip(b) # => [[12, 1], [11, 2], [21, nil]]
b.zip(a) # => [[1, 12], [2, 11]]
That to apply the #transpose
method a
and b
should be of the same size. But for applying #zip
, it is not needed b
to be of the same size of a
, ie b
and a
can be of any of size.
With #zip
, the resultant array size will always be the size of self
. With #transpose
the resulting array size will be any of the inner array's size of self
.
*
and+
since2+2
and2*2
do the same thing. – Zoes