Capture IRB session

Is there any way in irb to capture all of my input lines? I love to try
stuff out in there, but it gets really annoying copying out my work from
the sample output and all that. Anyway at the end of an irb session to
type in some command and have it spit out a full history into a string or
a file?

Thanks in advance.

-michael

Is there any way in irb to capture all of my input lines? I love to
try stuff out in there, but it gets really annoying copying out my
work from the sample output and all that. Anyway at the end of an irb
session to type in some command and have it spit out a full history
into a string or a file?

At the start you could do:

irb | tee some_file_name

Personally, because I use screen I use its copy and paste facilities.

cheers,

···


Iain.

Michael C. Libby wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is there any way in irb to capture all of my input lines? I love to try
stuff out in there, but it gets really annoying copying out my work from
the sample output and all that. Anyway at the end of an irb session to
type in some command and have it spit out a full history into a string or
a file?

This will put your input in a string which you can access from the
global var $lns:

module Readline

alias old_readline readline

def readline(*args,&block)
# “&block” just because I don’t know if it takes a block
ln = old_readline(*args,&block)
$lns ||= “”
$lns << ln + “\n” if ln
ln
end

end

There's always the Unix 'script' utility:

$ script foo
Script started, output file is foo
$ irb
irb(main):001:0> puts "hello, world!"
hello, world!
nil
irb(main):002:0> exit
$ exit
exit

Script done, output file is foo
$ cat foo
Script started on Fri Dec 13 23:20:30 2002
... session transcript

···

On Fri, Dec 13, 2002 at 10:22:33AM +0900, Michael C. Libby wrote:

Is there any way in irb to capture all of my input lines? I love to try
stuff out in there, but it gets really annoying copying out my work from
the sample output and all that. Anyway at the end of an irb session to
type in some command and have it spit out a full history into a string or
a file?

Brian Candler wrote:

Is there any way in irb to capture all of my input lines? I love to try
stuff out in there, but it gets really annoying copying out my work from
the sample output and all that. Anyway at the end of an irb session to
type in some command and have it spit out a full history into a string or
a file?

There’s always the Unix ‘script’ utility:

$ script foo
Script started, output file is foo
$ irb
irb(main):001:0> puts “hello, world!”
hello, world!
nil
irb(main):002:0> exit
$ exit
exit

Script done, output file is foo
$ cat foo
Script started on Fri Dec 13 23:20:30 2002
… session transcript

But that captures command-line editing control characters, output, …

If you just want input, put this in your .irbrc, assuming your irb is
built with readline support:

def dump_history(file=nil)
if file
File.open(file, “w”) do |f|
f.puts IRB::ReadlineInputMethod::HISTORY.to_a
end
else
puts IRB::ReadlineInputMethod::HISTORY.to_a
end
end

···

On Fri, Dec 13, 2002 at 10:22:33AM +0900, Michael C. Libby wrote: