Class: Producer::Core::Prompter
- Inherits:
-
Object
- Object
- Producer::Core::Prompter
- Defined in:
- lib/producer/core/prompter.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(input, output) ⇒ Prompter
constructor
A new instance of Prompter.
- #prompt(question, choices) ⇒ Object
Constructor Details
#initialize(input, output) ⇒ Prompter
Returns a new instance of Prompter.
6 7 8 9 |
# File 'lib/producer/core/prompter.rb', line 6 def initialize input, output @input = input @output = output end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
4 5 6 |
# File 'lib/producer/core/prompter.rb', line 4 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/producer/core/prompter.rb', line 4 def output @output end |
Instance Method Details
#prompt(question, choices) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/producer/core/prompter.rb', line 11 def prompt question, choices cs = choices.each_with_index.inject '' do |m, (c, i)| m + "#{i}: #{c.last}\n" end output.puts "#{question}\n#{cs}Choice:" choice = input.gets choices[choice.to_i].first end |