我有一个通知页面。就像社交网站上的任何通用通知页面一样。每个通知都有一个 unix 时间戳。我想根据天将通知划分为多维散列。哈希键可以表示它的日期。前任 :
notification['3July'][0] = 'Answered a question'
notification['3July'][1] = 'Answer got 13 upvotes'
notification['3July'][2] = 'Earned a badge'
....
notification['23June'][0] = 'Set a bounty of 50 credits'
notification['23June'][1] = 'Followed XYZ'
notification['23June'][2] = 'Added a question on stack overflow'
然后我将遍历多维散列并在每天发布通知。目前我从数据库中获取数据,格式如下:
notification[0] = { 'text' => 'Answered a question' , 'timestamp' => 123456 }
notification[1] = { 'text' => 'Answer got 13 upvotes' , 'timestamp' => 123456 }
notification[2] = { 'text' => 'Earned a badge' , 'timestamp' => 123456 }
....
notification[3] = { 'text' =>'Set a bounty of 50 credits' , 'timestamp' => 123456 }
notification[4] = { 'text' =>'Followed XYZ' , 'timestamp' => 123456 }
notification[5] = { 'text' =>'Added a question on stack overflow' , 'timestamp' => 123456 }
在 Ruby/Rails 中最干净和最优化的方法是什么?