Class: TTY::Prompt::AnswersCollector
- Inherits:
-
Object
- Object
- TTY::Prompt::AnswersCollector
- Defined in:
- lib/tty/prompt/answers_collector.rb
Instance Method Summary collapse
- #add_answer(answer) ⇒ Object
-
#call(&block) ⇒ Hash
Start gathering answers.
- #create_collector ⇒ Object
-
#initialize(prompt, options = {}) ⇒ AnswersCollector
constructor
Initialize answer collector.
-
#key(name, &block) ⇒ Object
Create answer entry.
Constructor Details
#initialize(prompt, options = {}) ⇒ AnswersCollector
Initialize answer collector
9 10 11 12 |
# File 'lib/tty/prompt/answers_collector.rb', line 9 def initialize(prompt, = {}) @prompt = prompt @answers = .fetch(:answers) { {} } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 |
# File 'lib/tty/prompt/answers_collector.rb', line 53 def method_missing(method, *args, &block) answer = @prompt.public_send(method, *args, &block) add_answer(answer) end |
Instance Method Details
#add_answer(answer) ⇒ Object
46 47 48 |
# File 'lib/tty/prompt/answers_collector.rb', line 46 def add_answer(answer) @answers[@name] = answer end |
#call(&block) ⇒ Hash
Start gathering answers
20 21 22 23 |
# File 'lib/tty/prompt/answers_collector.rb', line 20 def call(&block) instance_eval(&block) @answers end |
#create_collector ⇒ Object
41 42 43 |
# File 'lib/tty/prompt/answers_collector.rb', line 41 def create_collector self.class.new(@prompt) end |
#key(name, &block) ⇒ Object
Create answer entry
31 32 33 34 35 36 37 38 |
# File 'lib/tty/prompt/answers_collector.rb', line 31 def key(name, &block) @name = name if block answer = create_collector.(&block) add_answer(answer) end self end |