[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

irb request

Peña, Botp

10/6/2004 8:46:00 AM

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


2 Answers

Brian Schröder

10/6/2004 10:33:00 AM

0

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




--
Brian Schröder
http://ruby.brian-sch...


Joel VanderWerf

10/18/2004 10:32:00 PM

0

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