Class: Question
- Inherits:
-
Object
- Object
- Question
- Defined in:
- lib/quizm.rb
Instance Method Summary collapse
- #add_answer(answer) ⇒ Object
- #ask ⇒ Object
-
#initialize(text) ⇒ Question
constructor
A new instance of Question.
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 |
#ask ⇒ Object
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 |