Class: IO

Inherits:
Object show all
Defined in:
lib/roby/support.rb

Instance Method Summary collapse

Instance Method Details

#ask(question, default, output_io = STDOUT) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/roby/support.rb', line 19

def ask(question, default, output_io = STDOUT)
  output_io.print question
  output_io.flush
  loop do
 answer = readline.chomp.downcase
 if answer.empty?
    return default
 elsif answer == 'y'
    return true
 elsif answer == 'n'
    return false
 else
    output_io.print "\nInvalid answer, try again: "
    output_io.flush
 end
  end
end