IRB - correcting errors in blocks

H

Hardy Henneberg

Hi,

When running IRB, and I have made an error, I miss a facility, which
lets me correct the error and rerun, whitout the need to copy entire
blocks line by line. When running Unix scripts interactivly, it
concatenates blocks into one line making it easy to correct and rerun.

A great facility would also be to stream the lines in an IRB session to
a file.

I'm new to IRB, so forgive me and help me.

regards
Hardy
 
J

James Edward Gray II

A great facility would also be to stream the lines in an IRB
session to a file.

My .irbrc saves my irb history to a file, among other things. Maybe
that would help. Here's the file:

require 'irb/completion'
ARGV.concat [ "--readline" ]

if $0 == "irb"
IRB.conf[:pROMPT_MODE] = :SIMPLE

IRB.conf[:EVAL_HISTORY] = 1000
IRB.conf[:SAVE_HISTORY] = 100

HISTFILE = "~/.irb.hist"
MAXHISTSIZE = 100

begin
if defined? Readline::HISTORY
histfile = File::expand_path( HISTFILE )
if File::exists?( histfile )
lines = IO::readlines( histfile ).collect {|line| line.chomp}
puts "Read %d saved history commands from %s." %
[ lines.nitems, histfile ] if $DEBUG || $VERBOSE
Readline::HISTORY.push( *lines )
else
puts "History file '%s' was empty or non-existant." %
histfile if $DEBUG || $VERBOSE
end

Kernel::at_exit {
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems >
MAXHISTSIZE
$stderr.puts "Saving %d history lines to %s." %
[ lines.length, histfile ] if $VERBOSE || $DEBUG
File::eek:pen( histfile, File::WRONLY|File::CREAT|File::TRUNC )
{|ofh|
lines.each {|line| ofh.puts line }
}
}
end
end

def ri(*names)
system(%{ri #{names.map {|name| name.to_s}.join(" ")}})
end
end

James Edward Gray II
 

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,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top