gpt4 book ai didi

ruby - irb 历史保存但不加载

转载 作者:数据小太阳 更新时间:2023-10-29 08:42:46 28 4
gpt4 key购买 nike

我使用以下 .irbrc在 FreeBSD 上的 ruby​​ 2.3.5 下使用 irb:

require 'irb/completion'
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 10000
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:HISTORY_FILE] = "/home/ebot/.irb_history"

当我退出 irb 时,历史记录被保存到 /home/ebot/.irb_history正如预期的那样。但是,当我开始另一个 irb session 时,Readline::History列表为空并按下 <up>键无效。

我将以下代码放入我的 .irbrc :

  if File.exist?(IRB.conf[:HISTORY_FILE]) then
prev = ''
File.open(IRB.conf[:HISTORY_FILE]).each do |line|
line.chomp!
if line.length > 0 then
if line != prev then
puts "pushing hist <#{line}>"
Readline::HISTORY.push(line)
prev = line
end
end
end
end

当我用这个执行 irb 时,我看到上面输出的几行,但是历史仍然是空的:

% irb
irb(main):001:0> 1+1
=> 2
irb(main):002:0> 3+3
=> 6
irb(main):003:0> ^D

% cat .irb_history
1+1
3+3

% irb
pushing hist <1+1>
pushing hist <3+3>
irb(main):001:0> Readline::HISTORY.to_a
=> ["Readline::HISTORY.to_a"]

因此,irb 似乎在执行 .irbrc 后重置/清空此列表.

我该如何解决这个问题?

最佳答案

在 FreeBSD 上,ruby 需要使用 readline 支持进行编译,而不是 libedit。

关于ruby - irb 历史保存但不加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631322/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com