I have a class QuestionList
that stores a list of 'Question' objects.
class QuestionList
attr_accessor :questions
def initialize
@questions = []
end
end
I then add questions to the list and then "ask" these questions from my main class as so:
list = QuestionList.new
list.questions << Question.new(5, 3)
list.questions << Question.new(1, 5)
list.questions << Question.new(2, 4)
list.questions.each do |question|
puts "#{question.ask}"
end
where Question.ask
simply outputs the question as a string.
I'm not sure how acceptable it is to be writing to an instance variable from my main class using the <<
operator, and list.questions.push(Question.new(5, 3))
is even more unclear from the main class.
Would it be better to have a QuestionsList.add_question(question)
method?
The same goes for list.questions.each
- is this acceptable to be used in the main class?