Module: PutsUtils::PutsPrompt
- Defined in:
- lib/puts_utils/puts_prompt.rb
Instance Method Summary collapse
-
#puts_prompt(question, required: false, default: nil) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/MethodLength.
Instance Method Details
#puts_prompt(question, required: false, default: nil) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/puts_utils/puts_prompt.rb', line 7 def puts_prompt(question, required: false, default: nil) tries = 1 loop do STDOUT.print question answer = STDIN.gets.strip return answer if answer.present? return default if answer.empty? && required == false raise 'Value is required' if answer.empty? && required && tries == 3 puts 'Sorry, this is required – please try again' tries += 1 next end end |