2
我有我的代碼:紅寶石,運行命令行
class String
def freq
str = String "a string!"
self.upcase.each_char { |c| puts c + "!" }
str = text.split(" ")
wordFrequencies = Hash.new(0)
str.each { |str| wordFrequencies[str] += 1 }
wordFrequencies = wordFrequencies.sort_by {|a, b| b }
wordFrequencies.reverse!
wordFrequencies.each { |str, wordFrequencies | puts str + " " + wordFrequencies.to_s }
end
end
當我去命令行運行它,我做的:
ruby filename.rb
,然後什麼也沒有發生 - 任何人都可以解釋爲什麼..?
你寫了很多行之後才意識到它沒有做任何事情? – Stefan