Solution for: #89: view readline history in irb

Readline::HISTORY

27
puts Readline::HISTORY.to_a

Comments

  1. Beautiful! Thanks!

    John on January 18, 2013, 08:57 PM UTC
  2. If 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