從Date對象數組中創建哈希的最有效方式是月份是鍵和值是日期數組?目前,我有以下幾點。以Month爲鍵創建日期對象數組中的哈希
require 'date'
...
start, finish = args.start, args.end # Assume this has been implemented
date_map = {}
(start..finish).map do |date|
unless date_map.has_key? date.month then date_map[date.month] = [date]
else date_map[date.month] << date end
end
有沒有更高效的方法來完成上述代碼塊?
這是很酷。謝謝。 – idealistikz