Class: Answer

Inherits:
Object
  • Object
show all
Defined in:
lib/quiz/answer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#answerObject

Returns the value of attribute answer.



2
3
4
# File 'lib/quiz/answer.rb', line 2

def answer
  @answer
end

#kindObject

Returns the value of attribute kind.



2
3
4
# File 'lib/quiz/answer.rb', line 2

def kind
  @kind
end

#orderObject

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/quiz/answer.rb', line 16

def is_right?
  @kind == Quiz::RIGHT
end

#to_sObject



11
12
13
# File 'lib/quiz/answer.rb', line 11

def to_s
  "#{@order}. #{answer}"
end