Calling zip with a block

The Ruby Doc for #zip states:

zip(arg, ...) {|arr| block} → nil 

In other words, calling #zip with a block always return nil. Without block, it returns the result.

To use the result of zip, better pass it to somethig like #map:

a = [1, 2, 3]
b = [4 ,5 ,6]

a.zip(b)                          # => [[1, 4], [2, 5], [3, 6]]
a.zip(b) {|n| n.reduce(:*) }      # => nil
a.zip(b).map {|n| n.reduce(:*) }  # => [4, 10, 18]
Links to this page
#ruby