Class: Answer
Instance Attribute Summary collapse
-
#answer_text ⇒ Object
Returns the value of attribute answer_text.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#correct ⇒ Object
readonly
Returns the value of attribute correct.
-
#explanation ⇒ Object
Returns the value of attribute explanation.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #as_json ⇒ Object
- #correct? ⇒ Boolean
- #has_explanation? ⇒ Boolean
-
#initialize(answer_text, correct, explanation = nil) ⇒ Answer
constructor
A new instance of Answer.
Constructor Details
#initialize(answer_text, correct, explanation = nil) ⇒ Answer
Returns a new instance of Answer.
11 12 13 14 15 |
# File 'lib/ruql/answer.rb', line 11 def initialize(answer_text, correct, explanation=nil) @answer_text = answer_text @correct = !!correct # ensure boolean @explanation = explanation end |
Instance Attribute Details
#answer_text ⇒ Object
Returns the value of attribute answer_text.
3 4 5 |
# File 'lib/ruql/answer.rb', line 3 def answer_text @answer_text end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
5 6 7 |
# File 'lib/ruql/answer.rb', line 5 def builder @builder end |
#correct ⇒ Object (readonly)
Returns the value of attribute correct.
4 5 6 |
# File 'lib/ruql/answer.rb', line 4 def correct @correct end |
#explanation ⇒ Object
Returns the value of attribute explanation.
3 4 5 |
# File 'lib/ruql/answer.rb', line 3 def explanation @explanation end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
6 7 8 |
# File 'lib/ruql/answer.rb', line 6 def question @question end |
Instance Method Details
#<=>(other) ⇒ Object
8 |
# File 'lib/ruql/answer.rb', line 8 def <=>(other) ; self.answer_text <=> other.answer_text ; end |
#as_json ⇒ Object
17 18 19 |
# File 'lib/ruql/answer.rb', line 17 def as_json Hash(:text => @answer_text, :correct => @correct,:explanation => @explanation).compact end |
#correct? ⇒ Boolean
9 |
# File 'lib/ruql/answer.rb', line 9 def correct? ; !!correct ; end |
#has_explanation? ⇒ Boolean
10 |
# File 'lib/ruql/answer.rb', line 10 def has_explanation? ; !!explanation ; end |