Array to Hash Ruby

后端 未结 9 473
无人及你
无人及你 2021-01-29 17:43

Okay so here\'s the deal, I\'ve been googling for ages to find a solution to this and while there are many out there, they don\'t seem to do the job I\'m looking for.

Ba

9条回答
  •  离开以前
    2021-01-29 18:26

    Just use Hash.[] with the values in the array. For example:

    arr = [1,2,3,4]
    Hash[*arr] #=> gives {1 => 2, 3 => 4}
    

提交回复
热议问题