重构代码但输出不同

时间:2014-10-06 19:22:47

标签: ruby raise raiserror

def in_progress_students(subject)
  case subject
    when "1,2,3 Roll!"
        started = students_by_completed(:worldOne, "1")[true] || []
        finished = completed_students(subject) || []
    when "If Fuzz, Then Roll"
        started = students_by_completed(:worldOne, "4")[true] || []
        finished = completed_students(subject) || []
    when "Loopy Lesson"
        started = students_by_completed(:worldOne, "19")[true] || []
        finished = completed_students(subject) || []
    when "Test Your Skillz"
        started = students_by_completed(:worldOne, "31")[true] || []
        finished = completed_students(subject) || []
    when "Functions101"
        started = students_by_completed(:worldTwo, "1")[true] || []
        finished = completed_students(subject) || []
    when "FunctionPro"
        started = students_by_completed(:worldTwo, "4")[true] || []
        finished = completed_students(subject) || []
    when "FunctionsPlus"
        started = students_by_completed(:worldTwo, "15")[true] || []
        finished = completed_students(subject) || []
    when "BuggyBasics"
        started = students_by_completed(:worldThree, "1")[true] || []
        finished = completed_students(subject) || []
    when "LoopyBugs"
        started = students_by_completed(:worldThree, "8")[true] || []
        finished = completed_students(subject) || []
    when "FunkyBugs"
        started = students_by_completed(:worldThree, "3")[true] || []
        finished = completed_students(subject) || []
    when "Infestation"
        started = students_by_completed(:worldThree, "11")[true] || []
        finished = completed_students(subject) || []
  end
      started.select{|student| !finished.include? student}
    end

我试图通过这样做来重构此代码库:

IN_PROGRESS_LEVELS = {
  "1,2,3 Roll!" => [:worldOne, "1"],
  "If Fuzz, Then Roll" => [:worldOne, "4"],
  "Loopy Lesson" =>[:worldOne, "19"],
  "Test your Skillz" => [:worldOne, "31"],
  "Functions101" => [:worldTwo, "1"],
  "FunctionPro" => [:worldTwo, "4"],
  "FunctionsPlus" => [:worldTwo, "15"],
  "BuggyBasics" => [:worldThree, "1"],
  "LoopyBugs" => [:worldThree,"8"],
  "FunkyBugs" => [:worldThree,"3"],
  "Infestation" => [:worldThree, "11"]
}

def in_progress_students(subject)
  world, level = IN_PROGRESS_LEVELS[subject]
  started = students_by_completed(world, level)[true] || []
  finished = completed_students(subject) || []
  started.select{|student| !finished.include? student}
end

但我收到错误,我认为是因为我得到了不同的输出状态。我究竟做错了什么?

还有怎样才能通过使用raise错误修复它?

谢谢

0 个答案:

没有答案
相关问题