ask (HighLine)

    # File lib/highline.rb, line 208
      def ask( question, answer_type = String, &details ) # :yields: question
        @question ||= Question.new(question, answer_type, &details)

        return gather if @question.gather

        # readline() needs to handle it's own output, but readline only supports
        # full line reading.  Therefore if @question.echo is anything but true,
        # the prompt will not be issued. And we have to account for that now.
        say(@question) unless (@question.readline and @question.echo == true)
        begin
          @answer = @question.answer_or_default(get_response)
          unless @question.valid_answer?(@answer)
            explain_error(:not_valid)
            raise QuestionError
          end

          @answer = @question.convert(@answer)

          if @question.in_range?(@answer)
            if @question.confirm
              # need to add a layer of scope to ask a question inside a
              # question, without destroying instance data
              context_change = self.class.new(@input, @output, @wrap_at, @page_at)
              if @question.confirm == true
                confirm_question = "Are you sure?  "
              else
                # evaluate ERb under initial scope, so it will have
                # access to @question and @answer
                template  = ERB.new(@question.confirm, nil, "%")
                confirm_question = template.result(binding)
              end
              unless context_change.agree(confirm_question)
                explain_error(nil)
                raise QuestionError
              end
            end

            @answer
          else
            explain_error(:not_in_range)
            raise QuestionError
          end
        rescue QuestionError
          retry
        rescue ArgumentError, NameError => error
          raise if error.is_a?(NoMethodError)
          if error.message =~ /ambiguous/
            # the assumption here is that OptionParser::Completion#complete
            # (used for ambiguity resolution) throws exceptions containing
            # the word 'ambiguous' whenever resolution fails
            explain_error(:ambiguous_completion)
          else
            explain_error(:invalid_type)
          end
          retry
        rescue Question::NoAutoCompleteMatch
          explain_error(:no_completion)
          retry
        ensure
          @question = nil    # Reset Question object.
        end
      end