lib/wmiirc/menu.rb
##
# Shows a key_menu() containing the given choices (automatically
# prefixed with indices) and returns the index of the chosen item.
#
# If nothing was chosen, then nil is returned.
#
# ==== Parameters
#
# [prompt]
#   Instruction on what the user should enter or choose.
#
# [choices]
#   List of choices to present to the user.
#
Shows a key_menu() containing the given choices (automatically
prefixed with indices) and returns the index of the chosen item.

If nothing was chosen, then nil is returned.

Parameters

[prompt]
Instruction on what the user should enter or choose.

[choices]
List of choices to present to the user.
Shows a key_menu () containing the given choices ( automatically prefixed with indices ) and returns the index of the chosen item . If nothing was chosen then nil is returned . Parameters [ prompt ] Instruction on what the user should enter or choose . [ choices ] List of choices to present to the user .
def index_menu choices, prompt = nil
    indices = []
    choices.each_with_index do |c, i|
      indices << "#{i+1}. #{c}"
    end
    if target = key_menu(indices, prompt)
      index = target[/^\d+/].to_i-1
      if index >= 0 && index < choices.length
        index
      end
    end
  end
def index_menu choices , prompt = nil indices = [ ] choices . each_with_index do | c , i | indices << "#{i+1}. #{c}" end if target = key_menu ( indices , prompt ) index = target [ / ^ \d + / ] . to_i - 1 if index >= 0 && index < choices . length index end end end
Shows a key_menu() containing the given choices (automatically
prefixed with indices) and returns the index of the chosen item.
Shows a key_menu () containing the given choices ( automatically prefixed with indices ) and returns the index of the chosen item .
# use natural 1..N numbering # use array 0..N-1 numbering # ignore out of bounds index # (possibly entered by user)
choices
<not_specific>
prompt
<not_specific>