問題:
I want to get a specific output iterating a Ruby Hash. 我希望得到一個迭代Ruby Hash的特定輸出。
This is the Hash I want to iterate over: 這是我想迭代的哈希:
hash = {
1 => ['a', 'b'],
2 => ['c'],
3 => ['d', 'e', 'f', 'g'],
4 => ['h']
}
This is the output I would like to get: 這是我想得到的輸出:
1-----
a
b
2-----
c
3-----
d
e
f
g
4-----
h
In Ruby, how can I get such an output with my Hash ? 在Ruby中,如何使用Hash獲得這樣的輸出?
解決方案:
參考一: https://en.stackoom.com/question/59LX參考二: https://stackoom.com/question/59LX