Class: ULL::ETSII::Alu3177::Quiz::Question
- Inherits:
-
Object
- Object
- ULL::ETSII::Alu3177::Quiz::Question
- Defined in:
- lib/ULL-ETSII-Alu3177-Quiz/quiz.rb
Overview
Clase que representa una de pregunta a un test.
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(title, anss) ⇒ Question
constructor
Recibe un título title de la pregunta y el resto de parámetros son las posibles respuestas.
-
#to_s ⇒ Object
Representación visual de una pregunta en forma de String.
Constructor Details
#initialize(title, anss) ⇒ Question
Recibe un título title de la pregunta y el resto de parámetros son las posibles respuestas.
132 133 134 135 136 |
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 132 def initialize(title, anss) raise ArgumentError, "Title has to be a String, got #{title.class}" unless title.is_a? String @title = title @answers = anss end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
129 130 131 |
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 129 def answers @answers end |
#title ⇒ Object
Returns the value of attribute title.
129 130 131 |
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 129 def title @title end |
Instance Method Details
#to_s ⇒ Object
Representación visual de una pregunta en forma de String.
139 140 141 142 143 144 145 146 147 |
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 139 def to_s out = "# #{@title}".colorize(:light_blue) + "\n" i = 1 answers.each do |a| out << " [#{i}] #{a}\n" i += 1 end out end |