Module: Gem::UserInteraction
Overview
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 ConsoleUI or SilentUI.
Example:
class X
  include Gem::UserInteraction
  def get_answer
    n = ask("What is the meaning of life?")
  end
endInstance Attribute Summary
DefaultUserInteraction - Included
Instance Method Summary
- 
    
      #alert(statement, question = nil)  
    
    Displays an alert statement.
- 
    
      #alert_error(statement, question = nil)  
    
    Displays an error statementto the error output location.
- 
    
      #alert_warning(statement, question = nil)  
    
    Displays a warning statementto the warning output location.
- 
    
      #ask(question)  
    
    Asks a questionand returns the answer.
- 
    
      #ask_for_password(prompt)  
    
    Asks for a password with a prompt
- 
    
      #ask_yes_no(question, default = nil)  
    
    Asks a yes or no question.
- 
    
      #choose_from_list(question, list)  
    
    Asks the user to answer questionwith an answer from the givenlist.
- 
    
      #say(statement = '')  
    
    Displays the given statementon the standard output (or equivalent).
- 
    
      #terminate_interaction(exit_code = 0)  
    
    Terminates the RubyGems process with the given exit_code
- 
    
      #verbose(msg = nil)  
    
    Calls #say with msgor the results of the block if really_verbose is true.
DefaultUserInteraction - Included
Instance Method Details
#alert(statement, question = nil)
Displays an alert statement.  Asks a question if given.
# File 'lib/rubygems/user_interaction.rb', line 99
def alert statement, question = nil ui.alert statement, question end
#alert_error(statement, question = nil)
Displays an error statement to the error output location.  Asks a question if given.
# File 'lib/rubygems/user_interaction.rb', line 107
def alert_error statement, question = nil ui.alert_error statement, question end
#alert_warning(statement, question = nil)
Displays a warning statement to the warning output location.  Asks a question if given.
# File 'lib/rubygems/user_interaction.rb', line 115
def alert_warning statement, question = nil ui.alert_warning statement, question end
#ask(question)
Asks a question and returns the answer.
# File 'lib/rubygems/user_interaction.rb', line 122
def ask question ui.ask question end
#ask_for_password(prompt)
Asks for a password with a prompt
# File 'lib/rubygems/user_interaction.rb', line 129
def ask_for_password prompt ui.ask_for_password prompt end
#ask_yes_no(question, default = nil)
Asks a yes or no question.  Returns true for yes, false for no.
# File 'lib/rubygems/user_interaction.rb', line 136
def ask_yes_no question, default = nil ui.ask_yes_no question, default end
#choose_from_list(question, list)
Asks the user to answer question with an answer from the given list.
# File 'lib/rubygems/user_interaction.rb', line 143
def choose_from_list question, list ui.choose_from_list question, list end
#say(statement = '')
Displays the given statement on the standard output (or equivalent).
# File 'lib/rubygems/user_interaction.rb', line 150
def say statement = '' ui.say statement end
#terminate_interaction(exit_code = 0)
Terminates the RubyGems process with the given exit_code
# File 'lib/rubygems/user_interaction.rb', line 157
def terminate_interaction exit_code = 0 ui.terminate_interaction exit_code end
#verbose(msg = nil)
Calls #say with msg or the results of the block if really_verbose is true.
# File 'lib/rubygems/user_interaction.rb', line 165
def verbose msg = nil say(msg || yield) if Gem.configuration.really_verbose end