Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/quiz.rb
Constant Summary collapse
- WRONG =
:wrong
- RIGHT =
:right
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#questions ⇒ Object
Returns the value of attribute questions.
Instance Method Summary collapse
- #checkAnswers(answersUser) ⇒ Object
-
#initialize(name = "", &block) ⇒ Quiz
constructor
A new instance of Quiz.
- #question(text, answers) ⇒ Object
- #right ⇒ Object
- #to_s ⇒ Object
- #wrong ⇒ Object
Constructor Details
#initialize(name = "", &block) ⇒ Quiz
Returns a new instance of Quiz.
8 9 10 11 12 13 14 15 |
# File 'lib/quiz.rb', line 8 def initialize(name="",&block) self.name = name self.questions =[] @counter = 0 instance_eval &block end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/quiz.rb', line 6 def name @name end |
#questions ⇒ Object
Returns the value of attribute questions.
6 7 8 |
# File 'lib/quiz.rb', line 6 def questions @questions end |
Instance Method Details
#checkAnswers(answersUser) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/quiz.rb', line 45 def checkAnswers(answersUser) count = 0 i = 0 @questions.each do |q| if q.check(answersUser[i]) count +=1 end i +=1 end "Resultado: #{count}/#{@questions.size}" end |
#question(text, answers) ⇒ Object
17 18 19 20 21 |
# File 'lib/quiz.rb', line 17 def question(text,answers) q = Question.new(text,answers) @questions << q @counter = 0 end |
#right ⇒ Object
29 30 31 32 33 |
# File 'lib/quiz.rb', line 29 def right @counter +=1 [@counter, RIGHT] end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/quiz.rb', line 35 def to_s cadena = "" @questions.each do |m,i| cadena += "#{m}" end cadena end |
#wrong ⇒ Object
24 25 26 27 |
# File 'lib/quiz.rb', line 24 def wrong @counter += 1 [@counter, WRONG] end |