Method: DataDuck::Commands.prompt_choices
- Defined in:
- lib/dataduck/commands.rb
.prompt_choices(choices = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dataduck/commands.rb', line 21 def self.prompt_choices(choices = []) while true print "Enter a number 0 - #{ choices.length - 1}\n" choices.each_with_index do |choice, idx| choice_name = choice.is_a?(String) ? choice : choice[1] print "#{ idx }: #{ choice_name }\n" end choice = STDIN.gets.strip.to_i if 0 <= choice && choice < choices.length selected = choices[choice] return selected.is_a?(String) ? selected : selected[0] end end end |