Method: HighLine#ask

Defined in:
lib/highline.rb

#ask(template_or_question, answer_type = nil, &details) ⇒ Object

This method is the primary interface for user input. Just provide a question to ask the user, the answer_type you want returned, and optionally a code block setting up details of how you want the question handled. See #say for details on the format of question, and Question for more information about answer_type and what’s valid in the code block.

Raises EOFError if input is exhausted.

Parameters:

  • template_or_question (String, Question)

    what to ask

  • answer_type (Class) (defaults to: nil)

    to what class to convert the answer

  • details

    to be passed to Question.new

Returns:

  • answer converted to the class in answer_type



216
217
218
219
220
221
222
223
224
# File 'lib/highline.rb', line 216

def ask(template_or_question, answer_type = nil, &details)
  question = Question.build(template_or_question, answer_type, &details)

  if question.gather
    QuestionAsker.new(question, self).gather_answers
  else
    QuestionAsker.new(question, self).ask_once
  end
end