0
我試圖從數組中構建散列。基本上我想獲取數組的唯一字符串值並使用鍵構建散列。我還試圖弄清楚如何記錄這個獨特詞彙發生的次數。如何從數組中生成散列
#The text from the .txt file:
# **Bob and George are great! George and Sam are great.
#Bob, George, and sam are great!**
#The source code:
count_my_rows = File.readlines("bob.txt")
row_text = count_my_rows.join
puts row_text.split.uniq #testing to make sure array is getting filled
反正我已經試過http://ruby-doc.org/core/classes/Hash.html
我想我需要聲明一個空的哈希值與name.new開始我不知道怎麼雖然它填平。我假設通過數組的迭代填充散列。我開始認爲我需要將該值記錄爲一個單獨的數組,存儲它發生的時間和單詞,然後將散列鍵指定給它。
示例= {[「Bob」,2] => 1,[「George」,3],> = 2}
留下一些代碼,以便我可以仔細研究。