Sha256: 0b56a57a5725f9c150d62204e826c9576785ead35d86df1070fe0c57becfe11d

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

module Interactive
  class Question
    attr_accessor :question, :options

    def initialize(&block)
      yield self

      @options = Interactive::Options(Array(@options))

      raise ArgumentError, "question cannot be nil nor empty." if question.nil? || question.empty?
      @question_type = @options.has_hash? ? QuestionWithEagerFullExplanation.new(self) : QuestionWithLazyFullExplanation.new(self)
    end

    def ask_and_wait_for_valid_response(&block)
      @question_type.ask_and_wait_for_valid_response(&block)
    end

    def ask(&block)
      ask_and_wait_for_valid_response(&block)
    end

    private

    def response
      STDIN.gets.chomp
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interactive-0.4.0 lib/interactive/question.rb