Skip to Content Skip to Search

class Rails::Console::IRBConsole

Public class methods

Source code GitHub
# File railties/lib/rails/commands/console/console_command.rb, line 16
def initialize(app)
  @app = app

  require "irb"
  require "irb/completion"

  IRB::WorkSpace.prepend(BacktraceCleaner)
  IRB::ExtendCommandBundle.include(Rails::ConsoleMethods)
end

Public instance methods

Source code GitHub
# File railties/lib/rails/commands/console/console_command.rb, line 53
def colorized_env
  case Rails.env
  when "development"
    IRB::Color.colorize("dev", [:BLUE])
  when "test"
    IRB::Color.colorize("test", [:BLUE])
  when "production"
    IRB::Color.colorize("prod", [:RED])
  else
    Rails.env
  end
end
Source code GitHub
# File railties/lib/rails/commands/console/console_command.rb, line 26
def name
  "IRB"
end
Source code GitHub
# File railties/lib/rails/commands/console/console_command.rb, line 30
def start
  IRB.setup(nil)

  if !Rails.env.local? && !ENV.key?("IRB_USE_AUTOCOMPLETE")
    IRB.conf[:USE_AUTOCOMPLETE] = false
  end

  env = colorized_env
  app_name = @app.class.module_parent_name.underscore.dasherize
  prompt_prefix = "#{app_name}(#{env})"

  IRB.conf[:PROMPT][:RAILS_PROMPT] = {
    PROMPT_I: "#{prompt_prefix}> ",
    PROMPT_S: "#{prompt_prefix}%l ",
    PROMPT_C: "#{prompt_prefix}* ",
    RETURN: "=> %s\n"
  }

  # Respect user's choice of prompt mode.
  IRB.conf[:PROMPT_MODE] = :RAILS_PROMPT if IRB.conf[:PROMPT_MODE] == :DEFAULT
  IRB::Irb.new.run(IRB.conf)
end

Definition files