Skip to content

Instantly share code, notes, and snippets.

@jmhodges
Created July 2, 2009 05:44
Show Gist options
  • Save jmhodges/139284 to your computer and use it in GitHub Desktop.
Save jmhodges/139284 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment