Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个数组,
a = [1, 2] b = [:a]
我想得到结果
[[1, :a], [2, :a]]
有什么方法吗?
使用Array#product:
a = [1, 2] b = [:a] a.product(b) => [[1, :a], [2, :a]]
你也可以这样做
[a,b*a.size].transpose #=> [[1, :a], [2, :a]]