Class: AskQuestion

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

Instance Method Summary collapse

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

#askObject



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