问题:
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