20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/tycli/util/ask.rb', line 20
def self.ask_with_answers(question, possible_answers)
print "\n#{question}? ["
print_info = Proc.new {
possible_answers_string = possible_answers.each_with_index do |answer, i|
_answer = (i == 0) ? answer.underline : answer
print " " + _answer
print(" /") if i != possible_answers.length-1
end
print " ]\n"
}
print_info.call
answer = ""
loop do
print ">".green
answer = STDIN.gets.downcase.chomp
answer = "yes" if answer == "y"
answer = "no" if answer == "n"
if answer == ""
answer = possible_answers[0].downcase
print answer.yellow
end
break if possible_answers.map { |a| a.downcase }.include? answer
print "\nPossible answers are ["
print_info.call
end
answer
end
|