Class: TextAdventure::Question
- Inherits:
-
Object
- Object
- TextAdventure::Question
- Defined in:
- lib/text_adventure.rb
Instance Attribute Summary collapse
-
#question ⇒ Object
Returns the value of attribute question.
Instance Method Summary collapse
- #ask ⇒ Object
-
#initialize(data) ⇒ Question
constructor
A new instance of Question.
Constructor Details
#initialize(data) ⇒ Question
Returns a new instance of Question.
41 42 43 44 |
# File 'lib/text_adventure.rb', line 41 def initialize(data) @question = data['question'] @answer = data['answers'] end |
Instance Attribute Details
#question ⇒ Object
Returns the value of attribute question.
39 40 41 |
# File 'lib/text_adventure.rb', line 39 def question @question end |
Instance Method Details
#ask ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/text_adventure.rb', line 45 def ask begin puts @question @answer.each do |key,value| puts " (#{key}) #{value['text']}" end input = gets return @answer[input.strip]['key'] rescue puts 'No valid option' retry end return 'death' end |