How to iterate over an array of arrays

后端 未结 3 1975
不思量自难忘°
不思量自难忘° 2021-02-18 20:32

What\'s the best way to iterate over an array of arrays?

sounds = [ [Name_1, link_1], [Name_2, link_2], [Name_3, link_3], [Name_4, link_4] ]

I

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 21:06

    Assuming all the inner arrays have fixed size, you can use auto-unpacking to get each item of the inner array in its own variable when iterating over the outer array. Example:

    sounds.each do |name, link|
      # do something
    end
    

提交回复
热议问题