Class: Escape::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/escape/question.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, answer: nil) ⇒ Question

Returns a new instance of Question.



5
6
7
8
# File 'lib/escape/question.rb', line 5

def initialize(text, answer: nil)
  @text = text
  @answer = answer
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



3
4
5
# File 'lib/escape/question.rb', line 3

def answer
  @answer
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/escape/question.rb', line 3

def text
  @text
end

Class Method Details

.load(question) ⇒ Object



15
16
17
# File 'lib/escape/question.rb', line 15

def load(question)
  new(question["text"], answer: question["answer"])
end

Instance Method Details

#correct?(answer) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/escape/question.rb', line 10

def correct?(answer)
  self.answer.to_s == answer
end