我目前正在尝试干掉这个初始的详细代码:
def planting_dates_not_nil?
!plant_out_week_min.blank? || !plant_out_week_max.blank? || !sow_out_week_min.blank? || !sow_out_week_max.blank?
end
def needs_planting?(week)
if !plant_out_week_min.blank? && !plant_out_week_max.blank?
(plant_out_week_min..plant_out_week_max).include? (week)
end
end
def needs_sowing?(week)
if !sow_out_week_min.blank? && !sow_out_week_max.blank?
(sow_out_week_min..sow_out_week_max).include? (week)
end
end
def needs_harvesting?(week)
if !harvest_week_min.blank? && !harvest_week_max.blank?
(harvest_week_min..harvest_week_max).include? (week)
end
end
这是我的初步尝试:
def tasks_for_week(week,*task_names)
task_names.each do |task_name|
to_do_this_week = []
unless read_attribute(task_name).nil?
if (read_attribute("#{task_name}_week_min")..read_attribute("#{task_name}_week_max")).include? (week)
to_do_this_week << task_name
end
end
end
end
但是,当我在控制台中运行此代码时,如下所示:
p.tasks_for_week(Date.today.cweek, :plant_out, :sow_out])
我得到了一个意想不到的结果......即使不需要种植植物,我仍然会返回一个包含两个任务名称的数组( [:plant_out, :sow_out]
谁能让我知道我将如何清理它并让 tasksforweek 方法返回预期结果?
TIA