class Quiz

Constants

WRONG

Attributes

name[RW]
questions[RW]

Public Class Methods

new(name = "", &block) click to toggle source
# File lib/my_gem/quiz.rb, line 66
def initialize(name = "", &block)
  self.name = name
  self.questions = []

  @counter = 0
  instance_eval &block
end

Public Instance Methods

question(text, answers) click to toggle source
# File lib/my_gem/quiz.rb, line 74
def question(text, answers)
  q = Question.new(text, answers)
  questions << q
  @counter = 0
end
right() click to toggle source
# File lib/my_gem/quiz.rb, line 93
def right
  @counter+= 1
  [@counter, RIGHT]
end
run() click to toggle source
# File lib/my_gem/quiz.rb, line 102
def run
  counter=0
  puts self.name+"\n\n"
  self.questions.each { |q| counter += 1 if q.ask }
  puts "#{counter} respuestas correctas de un total de #{@questions.size}."
end
title(title) click to toggle source
# File lib/my_gem/quiz.rb, line 98
def title(title)
  @name = title
end
to_s() click to toggle source
# File lib/my_gem/quiz.rb, line 80
  def to_s
    out = <<"EOQUIZ"
#{self.name}

#{self.questions.join("\n")}
EOQUIZ
  end
wrong() click to toggle source
# File lib/my_gem/quiz.rb, line 88
def wrong
  @counter += 1
  [@counter, WRONG]
end