Class: Answer
- Inherits:
-
Object
- Object
- Answer
- Defined in:
- lib/quiz/answer.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
Returns the value of attribute answer.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Answer objects must be sorted according to their position inside the question.
-
#initialize(order, kind, answer) ⇒ Answer
constructor
order: the position of the answer in the question kind: either :right or :wrong answer: the text of the answer (for instance “1492”).
-
#is_right? ⇒ Boolean
decides if this is a right answer.
- #to_s ⇒ Object
Constructor Details
#initialize(order, kind, answer) ⇒ Answer
order: the position of the answer in the question kind: either :right or :wrong answer: the text of the answer (for instance “1492”)
7 8 9 |
# File 'lib/quiz/answer.rb', line 7 def initialize(order, kind, answer) @kind, @order, @answer = kind, order, answer end |
Instance Attribute Details
#answer ⇒ Object
Returns the value of attribute answer.
2 3 4 |
# File 'lib/quiz/answer.rb', line 2 def answer @answer end |
#kind ⇒ Object
Returns the value of attribute kind.
2 3 4 |
# File 'lib/quiz/answer.rb', line 2 def kind @kind end |
#order ⇒ Object
Returns the value of attribute order.
2 3 4 |
# File 'lib/quiz/answer.rb', line 2 def order @order end |
Instance Method Details
#<=>(other) ⇒ Object
Answer objects must be sorted according to their position inside the question
22 23 24 |
# File 'lib/quiz/answer.rb', line 22 def <=>(other) self.order <=> other.order end |
#is_right? ⇒ Boolean
decides if this is a right answer
16 17 18 |
# File 'lib/quiz/answer.rb', line 16 def is_right? @kind == Quiz::RIGHT end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/quiz/answer.rb', line 11 def to_s "#{@order}. #{answer}" end |