Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/Exam/quiz.rb
Instance Attribute Summary collapse
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#exam ⇒ Object
Returns the value of attribute exam.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Quiz
constructor
A new instance of Quiz.
- #question(*args) ⇒ Object
- #right ⇒ Object
- #run ⇒ Object
- #to_s ⇒ Object
- #wrong ⇒ Object
Constructor Details
Instance Attribute Details
#counter ⇒ Object
Returns the value of attribute counter.
5 6 7 |
# File 'lib/Exam/quiz.rb', line 5 def counter @counter end |
#exam ⇒ Object
Returns the value of attribute exam.
5 6 7 |
# File 'lib/Exam/quiz.rb', line 5 def exam @exam end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/Exam/quiz.rb', line 5 def name @name end |
Instance Method Details
#question(*args) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/Exam/quiz.rb', line 24 def question(*args) wrong = Array.new args[1].keys.each { |x| wrong << args[1][x] if x.instance_of?(Array)} @exam.push(Question.new(:qt => args[0], :r1 => args[1][:right], :wrong => wrong)) @exam end |
#right ⇒ Object
15 16 17 |
# File 'lib/Exam/quiz.rb', line 15 def right :right end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/Exam/quiz.rb', line 35 def run puts "#{@name}\n\n" punt = 0 right = @exam.right userans = Array.new(right.count, false) @exam.exam.each_with_index do |x, i| puts x print "Su respuesta es: " STDOUT.flush if right[i].to_s.eql?gets.chomp punt += 1 end puts "\n" end puts "Ha acertado #{punt} de #{right.count}" end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/Exam/quiz.rb', line 31 def to_s "\t#{@name}\n\n#{@exam}" end |
#wrong ⇒ Object
19 20 21 22 |
# File 'lib/Exam/quiz.rb', line 19 def wrong @counter += 1 [:wrong, @counter] end |