Class: Questions::Question
- Inherits:
-
Object
- Object
- Questions::Question
- Defined in:
- lib/questions/question.rb
Overview
You can ask a question with answers for selection. User can select one answer.
It’s also possible to specify answers as an Hash:
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
Class Method Summary collapse
-
.ask(question, answers) ⇒ Symbol
Asks question.
Instance Method Summary collapse
-
#ask ⇒ Symbol
Asks question to user.
-
#initialize(question) ⇒ Question
constructor
Instantiates a new Question object.
Constructor Details
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
32 33 34 |
# File 'lib/questions/question.rb', line 32 def answers @answers end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
31 32 33 |
# File 'lib/questions/question.rb', line 31 def question @question end |
Class Method Details
Instance Method Details
#ask ⇒ Symbol
Asks question to user. If user typed wrong indicator, then it will be asked again.
67 68 69 70 71 72 |
# File 'lib/questions/question.rb', line 67 def ask answers = answers() raise "You have to set answers" if answers.empty? answer = UserInput.get "#{@question} #{answers}" answers[answer.to_sym].instruction || ask end |