0
我是Ruby新手,並使用Learn Ruby the Hard Way在線書籍學習它。我不是很清楚EX39:http://learnrubythehardway.org/book/ex39.htmlRuby難以用ex39 .hash函數與%運算符
混淆代碼:
def Dict.hash_key(aDict, key)
# Given a key this will create a number and then convert it to
# an index for the aDict's buckets.
#takes the key arguments and converts it into a hash number
# that is divided by the length
#of the Dict. The remainder a number on the aDict.
return key.hash % aDict.length
end
什麼被用於%操作。如果key.has創建了一個唯一的數字,爲什麼我們需要將它除以Dict的長度?