1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/irb.rb, lib/irb/init.rb, lib/irb/ext/save-history.rb: add

IRB::irb_at_exit. no use finalizer saving history. [ruby-dev-38563]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
keiju 2009-07-21 15:39:51 +00:00
parent 4516f623b8
commit 24a510a11e
3 changed files with 40 additions and 19 deletions

View file

@ -1,3 +1,8 @@
Wed Jul 22 00:34:39 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb.rb, lib/irb/init.rb, lib/irb/ext/save-history.rb: add
IRB::irb_at_exit. no use finalizer saving history. [ruby-dev-38563]
Tue Jul 21 23:47:38 2009 Yusuke Endoh <mame@tsg.ne.jp> Tue Jul 21 23:47:38 2009 Yusuke Endoh <mame@tsg.ne.jp>
* random.c (rand_init): array length of random seed was broken, which * random.c (rand_init): array length of random seed was broken, which
@ -5,11 +10,11 @@ Tue Jul 21 23:47:38 2009 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_rand.c: test for above. * test/ruby/test_rand.c: test for above.
Tue Jul 21 21:37:19 2009 Keiju Ishitsuka <keiju@emperor2.pendome> Tue Jul 21 21:37:19 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb/cmd/help.rb: fixed irb's "help" command. [ruby-core:22310]. * lib/irb/cmd/help.rb: fixed irb's "help" command. [ruby-core:22310].
Tue Jul 21 20:41:20 2009 Keiju Ishitsuka <keiju@emperor2.pendome> Tue Jul 21 20:41:20 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/tracer.rb: no show lines unkonwn line number. [ruby-core:22096], * lib/tracer.rb: no show lines unkonwn line number. [ruby-core:22096],
no trace display c-call and c-return as default. no trace display c-call and c-return as default.
@ -618,7 +623,7 @@ Wed Jul 8 23:13:54 2009 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c (nucomp_div): omitted zero division check. * complex.c (nucomp_div): omitted zero division check.
Wed Jul 8 21:00:37 2009 Keiju Ishitsuka <keiju@emperor2.pendome> Wed Jul 8 21:00:37 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb/inspector.rb: forget svn add. * lib/irb/inspector.rb: forget svn add.

View file

@ -47,23 +47,24 @@ module IRB
module HistorySavingAbility module HistorySavingAbility
include Readline include Readline
def HistorySavingAbility.create_finalizer # def HistorySavingAbility.create_finalizer
proc do # proc do
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0 # if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
if history_file = IRB.conf[:HISTORY_FILE] # if hf = IRB.conf[:HISTORY_FILE]
history_file = File.expand_path(history_file) # file = File.expand_path(hf)
end # end
history_file = IRB.rc_file("_history") unless history_file # file = IRB.rc_file("_history") unless file
open(history_file, 'w' ) do |f| # open(file, 'w' ) do |f|
hist = HISTORY.to_a # hist = HISTORY.to_a
f.puts(hist[-num..-1] || hist) # f.puts(hist[-num..-1] || hist)
end # end
end # end
end # end
end # end
def HistorySavingAbility.extended(obj) def HistorySavingAbility.extended(obj)
ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer) # ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
IRB.conf[:AT_EXIT].push proc{obj.save_history}
obj.load_history obj.load_history
obj obj
end end
@ -79,5 +80,18 @@ module IRB
end end
end end
end end
def save_history
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
if history_file = IRB.conf[:HISTORY_FILE]
history_file = File.expand_path(history_file)
end
history_file = IRB.rc_file("_history") unless history_file
open(history_file, 'w' ) do |f|
hist = HISTORY.to_a
f.puts(hist[-num..-1] || hist)
end
end
end
end end
end end

View file

@ -113,6 +113,8 @@ module IRB
# @CONF[:LC_MESSAGES] = "en" # @CONF[:LC_MESSAGES] = "en"
@CONF[:LC_MESSAGES] = Locale.new @CONF[:LC_MESSAGES] = Locale.new
@CONF[:AT_EXIT] = []
@CONF[:DEBUG_LEVEL] = 1 @CONF[:DEBUG_LEVEL] = 1
end end