Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/simpleselect/quiz.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#questions ⇒ Object
Returns the value of attribute questions.
-
#titulo ⇒ Object
Returns the value of attribute titulo.
Instance Method Summary collapse
-
#initialize(titulo, &block) ⇒ Quiz
constructor
A new instance of Quiz.
- #question(name, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(titulo, &block) ⇒ Quiz
Returns a new instance of Quiz.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/simpleselect/quiz.rb', line 3 def initialize(titulo, &block) @titulo=titulo self.questions=[] self.answers=[] if block_given? if block.arity == 1 yield self else instance_eval &block end end end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
2 3 4 |
# File 'lib/simpleselect/quiz.rb', line 2 def answers @answers end |
#questions ⇒ Object
Returns the value of attribute questions.
2 3 4 |
# File 'lib/simpleselect/quiz.rb', line 2 def questions @questions end |
#titulo ⇒ Object
Returns the value of attribute titulo.
2 3 4 |
# File 'lib/simpleselect/quiz.rb', line 2 def titulo @titulo end |
Instance Method Details
#question(name, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simpleselect/quiz.rb', line 34 def question(name, = {}) q = name aux = [] if [:right] == nil puts "No hay una respuesta correcta" return end if [:wrong] == nil puts "No hay ninguna respuesta incorrecta" return end aux << " *) #{[:right]}" [:wrong].each do |w| aux << " *) #{w}" end questions << q answers << aux end |
#to_s ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simpleselect/quiz.rb', line 17 def to_s output = @titulo output << "\n#{'=' * titulo.size}\n" questions.each_with_index do |q, ind| output << "\n" output << q output <<"\n" answers[ind].each do |an| output << an output << "\n" end end output end |