Module | IRB::HistorySavingAbility |
In: |
lib/irb/ext/save-history.rb
|
def HistorySavingAbility.create_finalizer
proc 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
# File lib/irb/ext/save-history.rb, line 68 68: def HistorySavingAbility.extended(obj) 69: # ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer) 70: IRB.conf[:AT_EXIT].push proc{obj.save_history} 71: obj.load_history 72: obj 73: end
# File lib/irb/ext/save-history.rb, line 75 75: def load_history 76: hist = IRB.conf[:HISTORY_FILE] 77: hist = IRB.rc_file("_history") unless hist 78: if File.exist?(hist) 79: open(hist) do |f| 80: f.each {|l| HISTORY << l.chomp} 81: end 82: end 83: end
# File lib/irb/ext/save-history.rb, line 85 85: def save_history 86: if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0 87: if history_file = IRB.conf[:HISTORY_FILE] 88: history_file = File.expand_path(history_file) 89: end 90: history_file = IRB.rc_file("_history") unless history_file 91: open(history_file, 'w' ) do |f| 92: hist = HISTORY.to_a 93: f.puts(hist[-num..-1] || hist) 94: end 95: end 96: end