学生 - 课程。如何允许在类课程的初始化方法中设置类的天数?方法参数。红宝石

时间:2018-01-14 13:56:55

标签: ruby rspec

我目前正在制定学生课程计划。一切进展顺利,直到我发现自己难以理解谁允许我的初始化方法有一个参数days哪些值可能是一周中的任何一天:mon, :tue, ...

更具体地说,我正在努力的是,我应该在哪里以及如何包含可以包含在class Course

的initialize参数中的星期几列表

这就是我的课程到目前为止的样子:

    class Course

  attr_reader :department, :name, :credits, :time_block, :days, :students

  def initialize(course_name, department, credits, time_block = nil, days = nil)  # where should I include the list of symbols : :mon,:tue,:weds ... ?? , also time_block? 
    @course_name = course_name
    @department = department
    @credits = credits
    @students = []
    @days = days
    @time_block = time_block
  end


  def name
    @course_name
  end

  def department
    @department
  end

  def credits
    @credits
  end

  def add_student(student)
    return if @students.include?(student)
    student.enroll(self)
  end

  def conflicts_with?(course2)
    return false if self.time_block != course2.time_block

    days.any? do |day|
      course2.days.include?(day)
    end
  end

end

1 个答案:

答案 0 :(得分:1)

PdfStamper

是的,就这么简单。