UserInteraction allows RubyGems to interact with the user through standard methods that can be replaced with more-specific UI methods for different displays.
Since UserInteraction dispatches to a concrete UI class you may need to reference other classes for specific behavior such as Gem::ConsoleUI or Gem::SilentUI.
Example:
class X include Gem::UserInteraction def get_answer n = ask("What is the meaning of life?") end end
Displays an alert statement. Asks a question if
given.
# File rubygems/user_interaction.rb, line 99
def alert statement, question = nil
ui.alert statement, question
end
Displays an error statement to the error output location.
Asks a question if given.
# File rubygems/user_interaction.rb, line 107
def alert_error statement, question = nil
ui.alert_error statement, question
end
Displays a warning statement to the warning output location.
Asks a question if given.
# File rubygems/user_interaction.rb, line 115
def alert_warning statement, question = nil
ui.alert_warning statement, question
end
Asks a question and returns the answer.
# File rubygems/user_interaction.rb, line 122
def ask question
ui.ask question
end
Asks for a password with a prompt
# File rubygems/user_interaction.rb, line 129
def ask_for_password prompt
ui.ask_for_password prompt
end
Asks a yes or no question. Returns true for yes, false for
no.
# File rubygems/user_interaction.rb, line 136
def ask_yes_no question, default = nil
ui.ask_yes_no question, default
end
Asks the user to answer question with an answer from the given
list.
# File rubygems/user_interaction.rb, line 143
def choose_from_list question, list
ui.choose_from_list question, list
end
Displays the given statement on the standard output (or
equivalent).
# File rubygems/user_interaction.rb, line 150
def say statement = ''
ui.say statement
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.