# Irb request

**URL:** <https://rubytalk.org/t/irb-request/13988>\
**Category:** ruby-talk\
**Created:** [6 October 2004 08:45 UTC](https://rubytalk.org/t/irb-request/13988 "2004-10-06T08:45:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [6 October 2004 08:45 UTC](https://rubytalk.org/t/irb-request/13988/1 "2004-10-06T08:45:48Z")

</div>

Hi All:

Forgive me in advance for this stupid request:

How can I make irb work

from this:

> **···**
>
> ------------------  
> irb(main):015:0\> 1  
> =\> 1  
> irb(main):016:0\> 2+2  
> =\> 4  
> irb(main):017:0\>  
> irb(main):018:0\> 5.times{p "hello ruby"}  
> "hello ruby"  
> "hello ruby"  
> "hello ruby"  
> "hello ruby"  
> "hello ruby"  
> =\> 5  
> ------------------
> 
> to this:  
> ------------------  
> 1 #=\> 1  
> 2+2 #=\> 4
> 
> 5.times{p "hello ruby"} #"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#=\> 5  
> ------------------
> 
> iow,
> 
> 1. I want to remove the prompt char  
> 2. I want output of irb not to be placed right below, but right next at a  
> certain column (so that output aligns)  
> 3. I want the output prefixed w # char (easy for cut & paste)
> 
> thanks in advance  
> -botp

---

<div class="post-metadata">

**Author:** ![Brian\_SchrA\_der](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@Brian\_SchrA\_der](https://rubytalk.org/u/Brian_SchrA_der)\
**Post date:** [6 October 2004 10:32 UTC](https://rubytalk.org/t/irb-request/13988/2 "2004-10-06T10:32:41Z")

</div>

Peña, Botp wrote:

> Hi All:
> 
> Forgive me in advance for this stupid request:
> 
> How can I make irb work
> 
> from this:  
> ------------------  
> irb(main):015:0\> 1  
> =\> 1  
> irb(main):016:0\> 2+2  
> =\> 4  
> irb(main):017:0\>  
> irb(main):018:0\> 5.times{p "hello ruby"}  
> "hello ruby"  
> =\> 5  
> ------------------
> 
> to this:  
> ------------------  
> 1 #=\> 1  
> 2+2 #=\> 4
> 
> 5.times{p "hello ruby"} #"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#=\> 5  
> ------------------
> 
> iow,
> 
> 1. I want to remove the prompt char  
> 2. I want output of irb not to be placed right below, but right next at a  
> certain column (so that output aligns)  
> 3. I want the output prefixed w # char (easy for cut & paste)
> 
> thanks in advance  
> -botp

A partial answer is:  
$ irb --prompt-mode xmp  
1 + 2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==\>3  
5-3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==\>2

For more information read man irb

As i see it, it is not possible to get the output on the line. Maybe also investigate the emacs xmp package.

regards,

Brian

---- part of man irb ----

Customizing prompt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To costomize the prompt you set a variable

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.conf[:PROMPT]

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For example, describe as follows in `.irbrc'.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.conf[:PROMPT][:MY\_PROMPT] = { # name of prompt mode  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:PROMPT\_I =\> nil, # normal prompt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:PROMPT\_S =\> nil, # prompt for continuated strings  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:PROMPT\_C =\> nil, # prompt for continuated statement  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:RETURN =\> " ==\>%s\n" # format to return value  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Then, invoke irb with the above prompt mode by

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ irb1.8 --prompt my-prompt

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Or add the following in `.irbrc'.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.conf[:PROMPT\_MODE] = :MY\_PROMPT

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constants PROMPT\_I, PROMPT\_S and PROMPT\_C specifies the format. In the prompt specification, some special strings are available.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%N command name which is running  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%m to\_s of main object (self)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%M inspect of main object (self)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%l type of string(", ', /, ]), `]' is inner %w[...]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%NNi indent level. NN is degits and means as same as printf("%NNd").  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It can be ommited  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%NNn line number.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%% %  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For instance, the default prompt mode is defined as follows: IRB.conf[:PROMPT\_MODE][:DEFAULT] = {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROMPT\_I =\> "%N(%m):%03n:%i\> ",

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROMPT\_S =\> "%N(%m):%03n:%i%l ",

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROMPT\_C =\> "%N(%m):%03n:%i\* ",

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RETURN =\> "%s\n"}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RETURN is used to printf.

> **···**
>
> --  
> Brian Schröder  
> [http://ruby.brian-schroeder.de/](http://ruby.brian-schroeder.de/)

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [18 October 2004 22:32 UTC](https://rubytalk.org/t/irb-request/13988/3 "2004-10-18T22:32:05Z")

</div>

Peña, Botp wrote:

> Hi All:
> 
> Forgive me in advance for this stupid request:
> 
> How can I make irb work
> 
> from this:  
> ------------------  
> irb(main):015:0\> 1  
> =\> 1  
> irb(main):016:0\> 2+2  
> =\> 4  
> irb(main):017:0\>  
> irb(main):018:0\> 5.times{p "hello ruby"}  
> "hello ruby"  
> =\> 5  
> ------------------
> 
> to this:  
> ------------------  
> 1 #=\> 1  
> 2+2 #=\> 4
> 
> 5.times{p "hello ruby"} #"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"hello ruby"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#=\> 5  
> ------------------
> 
> iow,
> 
> 1. I want to remove the prompt char  
> 2. I want output of irb not to be placed right below, but right next at a  
> certain column (so that output aligns)  
> 3. I want the output prefixed w # char (easy for cut & paste)
> 
> thanks in advance  
> -botp

Sorry for the late reply--here's something Nobu came up with on ruby-talk a while ago:

In your .irbrc, put this line:

IRB.conf[:PROMPT][:XMP][:RETURN] = "# =\> %s\n"

Then run irb using the xmp mode as Brian suggested:

$ irb --prompt-mode xmp  
4  
# =\> 4

Not exactly what you asked for, but it's still useful for copy-pasting from irb into ruby-talk posts!

If you want to comment out stdout lines as well as irb's output lines, you might try modifying the STDOUT IO object to put a # at the beginning of each line.

HTH.
