Module: SwitchDb::Dialog

Defined in:
lib/switch_db/dialog.rb

Class Method Summary collapse

Class Method Details

.question?(message) ⇒ Boolean

rubocop:disable Performance/RegexpMatch

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
# File 'lib/switch_db/dialog.rb', line 4

def self.question?(message)
  loop do
    print(message + ' y/n ')
    answer = $stdin.gets.strip

    return true if /\A(?:y|yes)\z/i =~ answer
    return false if /\A(?:n|no)\z/i =~ answer
  end
end