我有一個2名員工的業務。每個員工都有很多消息。如何將散列添加到數組?
當我運行命令:
business.employees.each do |employee|
puts employee.messages.group_by &:from
end
我得到正確的輸出:
{100=>[#<Message id: 3, content: "Needs more training", from: 100, employee_id: 1>]}
{101=>[#<Message id: 2, content: "Very lazy.", from: 101, employee_id: 2>], 102=>[#<Message id: 1, content: "Fantastic.", created_at: "2014-03-03 12:01:28", updated_at: "2014-03-03 12:01:28", from: 102, employee_id: 2>]}
但我不想把我想要添加的每個哈希輸出到一個數組等等我可以展示他們。
所以,當我運行命令
grouped_messages = []
business.employees.each do |employee|
grouped_messages << employee.short_messages.group_by &:from
end
我得到的錯誤:expecting keyword_end
嘗試不忽略括號。 – sawa
我的第一個想法以及@sawa –