End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Gem::StreamUI#ask_yes_no
ask_yes_no(question, default=nil)
lib/rubygems/user_interaction.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/rubygems/user_interaction.rb, line 250
def ask_yes_no(question, default=nil)
unless tty?
if default.nil?
raise Gem::OperationNotSupportedError,
"Not connected to a tty and no default specified"
else
return default
end
end
default_answer = case default
when nil
'yn'
when true
'Yn'
else
'yN'
end
result = nil
while result.nil? do
result = case ask "#{question} [#{default_answer}]"
when /^y/i then true
when /^n/i then false
when /^$/ then default
else nil
end
end
return result
end
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.
See also
#ask_for_password
#backtrace
#ask
#choose_from_list
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1