我有一个包含数字的哈希:
{0=>0.07394653730860076,1=>0.0739598476853163,2=>0.07398647083461522}
它需要转换为如下数组:
[[0,0.07394653730860076],[1,0.0739598476853163],[2,0.07398647083461522]]
我尝试了我的hash.values让我:
[0.07398921877505593,0.07400253683443543,0.07402917535044515]
我尝试了多种方法,但我刚开始学习ruby.
解决方法
试试这个:
{0=>0.07394653730860076,2=>0.07398647083461522}.to_a #=> [[0,0.07398647083461522]]