123456789_123456789_123456789_123456789_123456789_

Module: Gem::UserInteraction

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/rubygems/user_interaction.rb

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
end

Instance Attribute Summary

Instance Method Summary

DefaultUserInteraction - Included

Text - Included

#clean_text

Remove any non-printable characters and make the text suitable for printing.

#format_text

Wraps text to wrap characters and optionally indents by indent characters.

#levenshtein_distance

Returns a value representing the “cost” of transforming str1 into str2 Vendored version of DidYouMean::Levenshtein.distance from the ruby/did_you_mean gem @ 1.4.0 github.com/ruby/did_you_mean/blob/2ddf39b874808685965dbc47d344cf6c7651807c/lib/did_you_mean/levenshtein.rb#L7-L37.

#truncate_text, #min3

Instance Method Details

#alert(statement, question = nil)

Displays an alert statement. Asks a question if given.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 101

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.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 109

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.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 117

def alert_warning(statement, question = nil)
  ui.alert_warning statement, question
end

#ask(question)

Asks a question and returns the answer.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 124

def ask(question)
  ui.ask question
end

#ask_for_password(prompt)

Asks for a password with a prompt

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 131

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.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 138

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.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 145

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).

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 152

def say(statement = "")
  ui.say statement
end

#terminate_interaction(exit_code = 0)

Terminates the RubyGems process with the given exit_code

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 159

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.

[ GitHub ]

  
# File 'lib/rubygems/user_interaction.rb', line 167

def verbose(msg = nil)
  say(clean_text(msg || yield)) if Gem.configuration.really_verbose
end