class Quiz

Attributes

counter[RW]
exam[RW]
name[RW]

Public Class Methods

new(name, &block) click to toggle source
# File lib/Exam/quiz.rb, line 7
def initialize(name, &block)
        @name = name
        @exam = Exam.new(Question.new(:qt => "-", :r1 => "-", :wrong => ["-"]))
        @exam.exam.pop
        @counter = 0
        instance_eval &block
end

Public Instance Methods

question(*args) click to toggle source
# 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() click to toggle source
# File lib/Exam/quiz.rb, line 15
def right
        :right
end
run() click to toggle source
# 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() click to toggle source
# File lib/Exam/quiz.rb, line 31
def to_s
        "\t#{@name}\n\n#{@exam}"
end
wrong() click to toggle source
# File lib/Exam/quiz.rb, line 19
def wrong
        @counter += 1
        [:wrong, @counter]
end