irb request

P

Peña, Botp

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"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#=> 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
 
B

Brian Schröder

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"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#=> 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
==>3
5-3
==>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
To costomize the prompt you set a variable

IRB.conf[:pROMPT]

For example, describe as follows in `.irbrc'.

IRB.conf[:pROMPT][:MY_PROMPT] = { # name of prompt mode
:pROMPT_I => nil, # normal prompt
:pROMPT_S => nil, # prompt for continuated strings
:pROMPT_C => nil, # prompt for continuated statement
:RETURN => " ==>%s\n" # format to return value
}

Then, invoke irb with the above prompt mode by

$ irb1.8 --prompt my-prompt

Or add the following in `.irbrc'.

IRB.conf[:pROMPT_MODE] = :MY_PROMPT

Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format.
In the prompt specification, some special strings are available.

%N command name which is running
%m to_s of main object (self)
%M inspect of main object (self)
%l type of string(", ', /, ]), `]' is inner %w[...]
%NNi indent level. NN is degits and means as same as
printf("%NNd").
It can be ommited
%NNn line number.
%% %
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"}
RETURN is used to printf.
 
J

Joel VanderWerf

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"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#"hello ruby"
#=> 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top