转换数组的最佳方法是什么?
arr = ["one", "two", "three", "four", "five"]
Run Code Online (Sandbox Code Playgroud)
哈希
{"one"=>0, "two"=>0, "three"=>0, "four"=>0, "five"=>0}
Run Code Online (Sandbox Code Playgroud)
我打算稍后用我自己的值填充'0',我现在只需要这个技术.
谢谢.
arr.product([0]).to_h
Run Code Online (Sandbox Code Playgroud)
或版本<2.0
Hash[arr.product([0])]
Run Code Online (Sandbox Code Playgroud)