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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roby/support.rb', line 13

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