🔍

No recent searches

# module Gem::UserInteraction

`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

### Public Instance Methods

alert (statement, question = nil)
Source

    # File lib/rubygems/user_interaction.rb, line 97
    def alert(statement, question = nil)
      ui.alert statement, question
    end

Displays an alert `statement`. Asks a `question` if given.

alert_error (statement, question = nil)
Source

    # File lib/rubygems/user_interaction.rb, line 105
    def alert_error(statement, question = nil)
      ui.alert_error statement, question
    end

Displays an error `statement` to the error output location. Asks a `question` if given.

alert_warning (statement, question = nil)
Source

    # File lib/rubygems/user_interaction.rb, line 113
    def alert_warning(statement, question = nil)
      ui.alert_warning statement, question
    end

Displays a warning `statement` to the warning output location. Asks a `question` if given.

ask (question)
Source

    # File lib/rubygems/user_interaction.rb, line 120
    def ask(question)
      ui.ask question
    end

Asks a `question` and returns the answer.

ask_for_password (prompt)
Source

    # File lib/rubygems/user_interaction.rb, line 127
    def ask_for_password(prompt)
      ui.ask_for_password prompt
    end

Asks for a password with a `prompt`

ask_yes_no (question, default = nil)
Source

    # File lib/rubygems/user_interaction.rb, line 134
    def ask_yes_no(question, default = nil)
      ui.ask_yes_no question, default
    end

Asks a yes or no `question`. Returns true for yes, false for no.

choose_from_list (question, list)
Source

    # File lib/rubygems/user_interaction.rb, line 141
    def choose_from_list(question, list)
      ui.choose_from_list question, list
    end

Asks the user to answer `question` with an answer from the given `list`.

say (statement = "")
Source

    # File lib/rubygems/user_interaction.rb, line 148
    def say(statement = "")
      ui.say statement
    end

Displays the given `statement` on the standard output (or equivalent).

terminate_interaction (exit_code = 0)
Source

    # File lib/rubygems/user_interaction.rb, line 155
    def terminate_interaction(exit_code = 0)
      ui.terminate_interaction exit_code
    end

Terminates the RubyGems process with the given `exit_code`

verbose (msg = nil) { || ... }
Source

    # File lib/rubygems/user_interaction.rb, line 163
    def verbose(msg = nil)
      say(clean_text(msg || yield)) if Gem.configuration.really_verbose
    end

Calls `say` with `msg` or the results of the block if really_verbose is true.