Module: Prompt

Included in:
Propre
Defined in:
lib/propre/prompt.rb

Class Method Summary collapse

Class Method Details

.yesno(prompt = 'Continue?', default = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/propre/prompt.rb', line 5

def Prompt.yesno(prompt = 'Continue?', default = false)
  a = ''
  s = default ? '[Y/n/s]' : '[y/N/s]'
  d = default ? 'y' : 'n'
  until %w[y n s].include? a
    a = ask("#{prompt} #{s} ") { |q| q.limit = 1; q.case = :downcase }
    a = d if a.length == 0
  end
  if a == 'y'; true elsif a == 's'; 'skip' else false end
end