jmhodges (owner)

Revisions

gist: 139284 Download_button fork
public
Public Clone URL: git://gist.github.com/139284.git
Embed All Files: show embed
irbrc_history_fix.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'irb/ext/save-history'
module IRB
  module HistorySavingAbility
    def HistorySavingAbility.create_finalizer
      at_exit do
        if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
          if hf = IRB.conf[:HISTORY_FILE]
            file = File.expand_path(hf)
          end
          file = IRB.rc_file("_history") unless file
          open(file, 'w' ) do |f|
            hist = HISTORY.to_a
            f.puts(hist[-num..-1] || hist)
          end
        end
      end
    end
    
    def HistorySavingAbility.extended(obj)
      HistorySavingAbility.create_finalizer
      
      obj.load_history
      obj
    end
  end
end