Module: Vpsb::AskSupport

Instance Method Summary collapse

Instance Method Details

#ask(&block) ⇒ Object



3
4
5
6
# File 'lib/vpsb/ask_support.rb', line 3

def ask(&block)
  yield if block
  STDIN.gets.chomp
end

#ask_loop(condition = nil, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/vpsb/ask_support.rb', line 17

def ask_loop(condition = nil, &block)
  condition ||= proc { |res| !res.strip.empty? }

  begin
    yield if block
    res = STDIN.gets.chomp
  end until condition.call(res)
  res
end

#ask_to_confirm(question) {|cond| ... } ⇒ Object

Yields:

  • (cond)


8
9
10
11
12
13
14
15
# File 'lib/vpsb/ask_support.rb', line 8

def ask_to_confirm(question, &block)
  answer = ask { puts "#{question} y[es]/n[o]?" }
  cond = (answer[0].to_s.downcase == 'y')

  yield cond if block

  cond
end