Combine two Arrays into Hash

前端 未结 7 1919
执笔经年
执笔经年 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:38

    This is the best and cleanest way to do what you want.

    Hash[members.zip(instruments.map{|i| i.include?(',') ? i.split(',') : i})]
    

    Enjoy!

提交回复
热议问题