ruby-win32/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb
# Ask a question.  Returns a true for yes, false for no.  If not
# connected to a tty, raises an exception if default is nil,
# otherwise returns default.
Ask a question.  Returns a true for yes, false for no.  If not
connected to a tty, raises an exception if default is nil,
otherwise returns default.
Ask a question . Returns a true for yes false for no . If not connected to a tty raises an exception if default is nil otherwise returns default .
def ask_yes_no(question, default=nil)
      if not @ins.tty? then
        if default.nil? then
          raise(
              Gem::OperationNotSupportedError,
              "Not connected to a tty and no default specified")
        else
          return default
        end
      end
      qstr = case default
      when nil
        'yn'
      when true
        'Yn'
      else
        'yN'
      end
      result = nil
      while result.nil?
        result = ask("#{question} [#{qstr}]")
        result = case result
        when /^[Yy].*/
          true
        when /^[Nn].*/
          false
        when /^$/
          default
        else
          nil
        end
      end
      return result
    end
def ask_yes_no ( question , default = nil ) if not @ins . tty? then if default . nil? then raise ( Gem :: OperationNotSupportedError , "Not connected to a tty and no default specified" ) else return default end end qstr = case default when nil 'yn' when true 'Yn' else 'yN' end result = nil while result . nil? result = ask ( "#{question} [#{qstr}]" ) result = case result when / ^[Yy].* / true when / ^[Nn].* / false when / ^$ / default else nil end end return result end
Ask a question.
Ask a question .
question
default