Class: Question

Inherits:
Object
  • Object
show all
Defined in:
lib/quizm.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Question

Returns a new instance of Question.



3
4
5
6
# File 'lib/quizm.rb', line 3

def initialize( text )
  @text = text
  @answers = []
end

Instance Method Details

#add_answer(answer) ⇒ Object



8
9
10
# File 'lib/quizm.rb', line 8

def add_answer(answer)
  @answers << answer
end

#askObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/quizm.rb', line 12

def ask
  puts ""
  puts "Question: #{@text}"
  @answers.size.times do |i|
    puts "#{i+1} - #{@answers[i].text}"
  end
  print "Enter answer: "
  answer = gets.to_i - 1
  return @answers[answer].correct
end