# File lib/adhearsion/voip/asterisk/commands.rb, line 71
        def menu(*args, &block)
          menu_instance = Menu.new(*args, &block)

          initial_digit_prompt = menu_instance.sound_files.any?

          # This method is basically one big begin/rescue block. When we
          # start the Menu object by continue()ing into it, it will pass
          # messages back to this method in the form of exceptions.
          begin
            # When enter!() is sent, this menu() implementation should handle
            # the is sent via an Exception subclass.
            unless menu_instance.should_continue?
              menu_instance.execute_failure_hook
              return :failed 
            else
              menu_instance.continue
            end
          rescue Menu::MenuResult => result_of_menu
            case result_of_menu
              when Menu::MenuResultInvalid
                menu_instance.execute_invalid_hook
                menu_instance.restart!
              when Menu::MenuGetAnotherDigit
                
                next_digit = play_files_in_menu menu_instance
                if next_digit
                  menu_instance << next_digit
                else
                  # The user timed out entering another digit!
                  case result_of_menu
                    when Menu::MenuGetAnotherDigitOrFinish
                      # This raises a ControlPassingException
                      redefine_extension_to_be result_of_menu.new_extension
                      jump_to_context_with_name result_of_menu.context_name
                    when Menu::MenuGetAnotherDigitOrTimeout
                      # This should execute premature_timeout AND reset if the number of retries
                      # has not been exhausted.
                      menu_instance.execute_timeout_hook
                      menu_instance.restart!
                  end
                end
              when Menu::MenuResultFound
                redefine_extension_to_be result_of_menu.new_extension
                jump_to_context_with_name result_of_menu.context_name
              else
                raise "Unrecognized MenuResult! This may be a bug!"
            end

            # Retry will re-execute the begin block, preserving our changes to the
            # menu_instance object.
            retry

          end
        end