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.
我有一个类似的数组prods[[1,2] [3,4]],其中第一个元素(1,3)是product_id,第二个元素(2,4)是数量。我需要列出所有产品及其数量。
prods[[1,2] [3,4]]
您可以迭代数组:
[[1,2],[3,4]].each { |product_id,qty| puts "#{product_id} => #{qty}" }
输出:
1 => 2 3 => 4