3 ms·
history function for ruby console (irb) sessions: def history(num=100) h = Readline::HISTORY.to_a start = [0,h.size-num-1].max h.zip((0..h.si
by klochner 15y ago
history function for ruby console (irb) sessions:
def history(num=100)
h = Readline::HISTORY.to_a
start = [0,h.size-num-1].max
h.zip((0..h.size).to_a)[start...h.size].each do |cmd,i|
puts " #{(i).to_s.rjust(4)} #{cmd}"
end
end
I keep it in my .irbrc file, really useful to avoid stepping through command history to find previous commands.