Skip to content

Instantly share code, notes, and snippets.

@flomotlik
Created March 16, 2012 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flomotlik/2051609 to your computer and use it in GitHub Desktop.
Save flomotlik/2051609 to your computer and use it in GitHub Desktop.
Thor select action
def select msg, elements
elements.each_with_index do |element, index|
say(block_given? ? yield(element, index + 1) : ("#{index + 1}. #{element.to_s}"))
end
result = ask(msg, :limited_to => (1..elements.count).map(&:to_s), :print_limits => false).to_i
elements[result - 1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment