Class: AskQuestion
- Inherits:
-
Object
- Object
- AskQuestion
- Defined in:
- lib/cear/ask_question/ask_question.rb
Instance Method Summary collapse
- #ask ⇒ Object
-
#initialize(__question, __default = nil) ⇒ AskQuestion
constructor
A new instance of AskQuestion.
Constructor Details
#initialize(__question, __default = nil) ⇒ AskQuestion
Returns a new instance of AskQuestion.
2 3 4 5 |
# File 'lib/cear/ask_question/ask_question.rb', line 2 def initialize(__question, __default = nil) @question = __question @default = __default end |
Instance Method Details
#ask ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cear/ask_question/ask_question.rb', line 7 def ask line = nil while line == nil print "#{@question} #{@default ? "[#{@default}] " : ""}" STDOUT.flush line = STDIN.gets.chomp if line.empty? if @default return @default else line = nil end end end return line.downcase end |