2006-11-27 05:49:45 +01:00
|
|
|
[[Kategorie:Wissen]][[Kategorie:Ruby]]
|
2006-05-27 09:40:22 +02:00
|
|
|
|
|
|
|
Den folgenden Code einfach in die ~/.irbrc tun und schon steht die besschriebene Funktionalität zur Verfügung.
|
|
|
|
|
2006-02-12 03:10:25 +01:00
|
|
|
=History=
|
|
|
|
<pre>
|
|
|
|
HISTFILE = "~/.irb.hist"
|
|
|
|
MAXHISTSIZE = 10000
|
|
|
|
|
|
|
|
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::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
|
|
|
|
lines.each {|line| ofh.puts line }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
</pre>
|
2006-02-12 03:08:05 +01:00
|
|
|
=ri in irb=
|
|
|
|
<pre>
|
|
|
|
def ri arg
|
|
|
|
puts `ri #{arg}`
|
|
|
|
end
|
|
|
|
class Module
|
|
|
|
def ri(meth=nil)
|
|
|
|
if meth
|
|
|
|
if instance_methods(false).include? meth.to_s
|
|
|
|
puts `ri #{self}##{meth}`
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
else
|
|
|
|
puts `ri #{self}`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
</pre>
|
2006-05-27 09:37:42 +02:00
|
|
|
=Tab completion und Einrückung=
|
2006-02-12 03:08:05 +01:00
|
|
|
<pre>
|
2006-05-27 09:37:42 +02:00
|
|
|
IRB.conf[:AUTO_INDENT] = true
|
|
|
|
IRB.conf[:USE_READLINE] = true
|
|
|
|
IRB.conf[:LOAD_MODULES] ||= []
|
|
|
|
IRB.conf[:LOAD_MODULES] |= ['irb/completion']
|
2006-02-12 03:08:05 +01:00
|
|
|
</pre>
|
2006-05-18 21:23:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{Rübÿ Spëëd Mëtäl Cödïng}}
|