Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

Ruby Programming
Previous Page Home Next Page

Configuring the Prompt

You have a lot of flexibility in configuring the prompts that irb uses. Sets of prompts are stored in the prompt hash:

IRB.conf[:PROMPT]

For example, to establish a new prompt mode called ``MY_PROMPT'', you might enter the following (either directly at an irb prompt or in the .irbrc file):

IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
  :PROMPT_I => "...",             # normal prompt
  :PROMPT_S => "...",             # prompt for continuing strings
  :PROMPT_C => "...",             # prompt for continuing statement
  :RETURN => "    ==>%s\n"        # format to return value
}

Then, invoke irb with the prompt mode above by

% irb --prompt my-prompt

Or set the following configuration value:

IRB.conf[:PROMPT_MODE] = :MY_PROMPT

The constants PROMPT_I, PROMPT_S, and PROMPT_C specify the format for each of the prompt strings. Within the prompt format, the following flags are available and will expand to the given text:

Flag Description
%N Current command.
%m to_s of the main object (self).
%M inspect of the main object (self).
%l Delimiter type. In strings that are continued across a line break, %l will display the type of delimiter used to begin the string, so you'll know how to end it. The delimiter will be one of ", ', /, ], or `.
%ni Indent level. The optional number n is used as a width specification to printf, as printf("%nd").
%nn Current line number (n used as with the indent level).
%% A literal percent sign.

For instance, the default prompt mode is defined as follows:

IRB.conf[:PROMPT_MODE][:DEFAULT] = {
      :PROMPT_I => "%N(%m):%03n:%i> ",
      :PROMPT_S => "%N(%m):%03n:%i%l ",
      :PROMPT_C => "%N(%m):%03n:%i* ",
      :RETURN => "%s\n"
}
Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire