Module: Input
- Defined in:
- lib/input.rb
Class Method Summary collapse
-
.non_empty ⇒ Object
Ensures the user enters a non-empty value.
-
.yes_no_or_refine ⇒ Object
Ensures the user enters “y” or “n”.
-
.yes_or_no ⇒ Object
Ensures the user enters “y” or “n”.
Class Method Details
.non_empty ⇒ Object
Ensures the user enters a non-empty value
3 4 5 6 7 8 9 10 |
# File 'lib/input.rb', line 3 def self.non_empty input = STDIN.gets.chomp.strip while input.length == 0 puts 'Please enter a non-empty value:'.colorize(:yellow) input = STDIN.gets.chomp.strip end input end |
.yes_no_or_refine ⇒ Object
Ensures the user enters “y” or “n”
23 24 25 26 27 28 29 30 |
# File 'lib/input.rb', line 23 def self.yes_no_or_refine input = STDIN.gets.chomp.downcase while ['y', 'n', 'r'].include?(input) == false puts 'Please enter "y/Y", "n/N" or "r/R":'.colorize(:yellow) input = STDIN.gets.chomp.downcase end input end |
.yes_or_no ⇒ Object
Ensures the user enters “y” or “n”
13 14 15 16 17 18 19 20 |
# File 'lib/input.rb', line 13 def self.yes_or_no input = STDIN.gets.chomp.downcase while ['y', 'n'].include?(input) == false puts 'Please enter "y/Y" or "n/N":'.colorize(:yellow) input = STDIN.gets.chomp.downcase end input end |