Method: HighLine::Menu#choices

Defined in:
lib/highline/menu.rb

#choices(*names, &action) ⇒ void

This method returns an undefined value.

A shortcut for multiple calls to the sister method #choice. Be warned: An action set here will apply to all provided names. This is considered to be a feature, so you can easily hand-off interface processing to a different chunk of code. choice has more options available to you, like longer text or help (and of course, individual actions)

Examples:

Implicit menu creation through HighLine#choose

cli = HighLine.new
answer = cli.choose do |menu|
  menu.prompt = "Please choose your favorite programming language?  "
  menu.choice(:ruby) { say("Good choice!") }
  menu.choices(:python, :perl) { say("Not from around here, are you?") }
end

Parameters:

  • names (Array<#to_s>)

    menu item titles/headers/names to be displayed.

  • action (Proc)

    callback action to be run when the item is selected.



237
238
239
# File 'lib/highline/menu.rb', line 237

def choices(*names, &action)
  names.each { |n| choice(n, &action) }
end