Sayuj
Sayuj

Reputation: 7622

Ruby - Array multiplication or JOIN operation

I have two arrays,

a = [1, 2]
b = [:a]

I want to get the result as

[[1, :a], [2, :a]]

Is there any methods for this?

Upvotes: 3

Views: 1170

Answers (2)

fl00r
fl00r

Reputation: 83680

Also you can do it this way

[a,b*a.size].transpose
#=> [[1, :a], [2, :a]]

Upvotes: 0

Roland Mai
Roland Mai

Reputation: 31077

Use the Array#product:

a = [1, 2]
b = [:a]
a.product(b)
=> [[1, :a], [2, :a]]

Upvotes: 6

Related Questions