Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - Array multiplication or JOIN operation

Tags:

arrays

ruby

set

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?

like image 684
Sayuj Avatar asked Feb 17 '26 16:02

Sayuj


1 Answers

Use the Array#product:

a = [1, 2]
b = [:a]
a.product(b)
=> [[1, :a], [2, :a]]
like image 130
Candide Avatar answered Feb 19 '26 05:02

Candide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!