从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