如何获取在Ruby中迭代哈希的特定输出? - How to get a specific output iterating a hash in Ruby?

问题:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章