class Quiz

Attributes

answers[RW]
questions[RW]
titulo[RW]

Public Class Methods

new(titulo) { |self| ... } click to toggle source
# 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

Public Instance Methods

question(name, options = {}) click to toggle source
# File lib/simpleselect/quiz.rb, line 34
 def question(name, options = {})
  q = name
  aux = []
  if options[:right] == nil
     puts "No hay una respuesta correcta"
      return
  end
  if options[:wrong] == nil
      puts "No hay ninguna respuesta incorrecta"
      return
  end
  
  aux << " *) #{options[:right]}" 
  options[:wrong].each do |w|
      aux << " *) #{w}"  
  end
  questions << q
  answers << aux
end
to_s() click to toggle source
# 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