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