class Question

Constants

KIND
ORDER

Attributes

answers[RW]
text[RW]

Public Class Methods

new(text, answers) click to toggle source
# File lib/my_gem/quiz.rb, line 29
def initialize(text, answers)
  @text = text

  @answers = answers.map { |k, v| Answer.new(k[ORDER], k[KIND],  v) }.sort
end

Public Instance Methods

ask() click to toggle source
# File lib/my_gem/quiz.rb, line 49
def ask
  begin
    puts self
    print "Su respuesta: " 
    answerno = gets.to_i - 1
  end while (answerno < 0 or answerno >= @answers.length)
  @answers[answerno].is_right? 
end
to_s() click to toggle source
# File lib/my_gem/quiz.rb, line 35
  def to_s
    output = <<"EOQ"
#{@text}

#{
    out = ""
    @answers.each do |answer|
      out << "  #{answer}\n"
    end
    out
}
EOQ
  end