LoginSignup
2
1

More than 5 years have passed since last update.

配列valuesと、valuesと同じ要素数の配列keysを結合して、keyをキーとする値valueのHashを作る方法

Posted at
keys=[:orange, :apple, :banaba, :strawberry, :blueberry]
values=[3,2,2,50,100]

hash_fruits=Hash[*[keys,values].transpose.flatten]

p hash_fruits

実行結果

{:orange=>3, :apple=>2, :banaba=>2, :strawberry=>50, :blueberry=>100}

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1