#89: view readline history in irb
Solved!
I wanted to view a log of all the lines I'd written in an IRB session, but didn't see a simple equivalent of bash's "history" command.
kueda out by posting your solution
kueda on April 01, 2010, 07:01 PM UTC
Comments
Beautiful! Thanks!
— John on January 18, 2013, 08:57 PM UTCIf you want to wrap it up, add this to your ~/.irbrc file (which gets loaded before your irb sessions):
def irb_history( count = nil )
hist = Readline::HISTORY.to_a
if count
len = hist.length
from = len - count
from = 0 if from < 0
puts "len: #{len}, count: #{count}, from: #{from}, hist.class: #{hist.class}, hist.length: #{hist.length}"
hist[from..-1]
else
hist
end
end
I'm not sure how the formatting will work.
— Bryce on June 23, 2014, 09:02 PM UTC