【发布时间】:2009-07-28 06:14:01
【问题描述】:
我有两个任务数组 - 创建和分配。 我想从创建的任务数组中删除所有分配的任务。 这是我的工作,但混乱的代码:
@assigned_tasks = @user.assigned_tasks
@created_tasks = @user.created_tasks
#Do not show created tasks assigned to self
@created_not_doing_tasks = Array.new
@created_tasks.each do |task|
unless @assigned_tasks.include?(task)
@created_not_doing_tasks << task
end
end
我确信有更好的方法。它是什么? 谢谢:-)
【问题讨论】:
-
我敢打赌,答案就是按照您在此处编写的代码。
标签: ruby arrays array-difference