What is the Ruby way to achieve following?
a = [1,2]
b = [3,4]
I want an array:
=> [f(1,3) ,f(1,4) , f(2,3) ,f(2,4)]
>
Facets has Array#product
which will give you the cross product of arrays. It is also aliased as the ** operator
for the two-array case. Using that, it would look like this:
require 'facets/array'
a = [1,2]
b = [3,4]
(a.product b).collect {|x, y| f(x, y)}
If you are using Ruby 1.9, product is a built-in Array function.