Combine two Arrays into Hash

前端 未结 7 1909
执笔经年
执笔经年 2020-12-01 01:44

I\'ve got two Arrays:

members     = [\"Matt Anderson\", \"Justin Biltonen\", \"Jordan Luff\", \"Jeremy London\"]
instruments = [\"guitar, vocals\", \"guitar\         


        
7条回答
  •  一向
    一向 (楼主)
    2020-12-01 02:37

    h = {}
    members.each_with_index do |el,ix|
        h[el] = instruments[ix].include?(",") ? instruments[ix].split(",").to_a : instruments[ix]
    end
    h
    

提交回复
热议问题