Reputation: 887
I have an array of values I got from a table:
arr = ["One", "0", "31.948", "0", "6.94",
"Two", "0", "31.948", "0", "6.94",
"Three", "0", "23.961", "0", "5.21"]
I need to get a hash of arrays:
hash = {
"One" => ["0", "31.948", "0", "6.94"],
"Two" => ["0", "31.948", "0", "6.94"],
"Three" => ["0", "23.961", "0", "5.21"]
}
How do I do it?
Upvotes: 1
Views: 101
Reputation: 168081
Assuming you want an array for each value, this will do it.
Hash[arr.each_slice(5).map{|k, *v| [k, v]}]
Upvotes: 6