Class: UserInput::Prompt
- Inherits:
-
Object
- Object
- UserInput::Prompt
- Defined in:
- lib/userinput/prompt.rb
Overview
Prompt object
Direct Known Subclasses
Instance Method Summary collapse
-
#ask ⇒ Object
Request user input.
-
#initialize(params = {}, &block) ⇒ Prompt
constructor
Build new prompt object and set defaults.
Constructor Details
#initialize(params = {}, &block) ⇒ Prompt
Build new prompt object and set defaults
9 10 11 12 13 14 15 16 17 |
# File 'lib/userinput/prompt.rb', line 9 def initialize(params = {}, &block) @attempts = params[:attempts] = params[:message] || '' @separator = params[:separator] || '?' @default = params[:default] @secret = params[:secret] || false @fd = params[:fd] || STDOUT @validation = block || params[:validation] end |
Instance Method Details
#ask ⇒ Object
Request user input
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/userinput/prompt.rb', line 21 def ask @fd.print disable_echo if @secret input = _ask return input if valid(input) check_counter ask ensure enable_echo if @secret end |