gpt4 book ai didi

ruby - 尝试在自定义 pry 命令中运行 pry 命令

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

我正在尝试自定义我的 Pry(使用 Pry 有一段时间了,但这是我第一次尝试创建命令。)我想创建一个自定义命令,它将获取最后五十个项目根据我的历史,我正在构建它:

Pry::Commands.block_command "fifty", "List the last fifty inputs" do
hist --tail=50 -a
end

一旦它出现在我的 .pryrc 文件中,它就会显示我是否“帮助五十”,但如果我尝试运行命令,我会得到以下信息:

NameError: undefined local variable or method `a' for #<#<Class:0x007f8a1ee49aa8>:0x007f8a1e873ed0>

我的猜测是命令在执行 block 中的范围存在一些问题,但我对 Pry 文档的搜索没有给我任何关于如何继续的想法。其他不尝试复制 Pry cl 命令的命令,例如示例中的命令

Pry::Commands.block_command "hello", "Say hello to three people" do |x, y, z|
output.puts "hello there #{x}, #{y}, and #{z}!"
end

工作正常。感谢任何输入。

最佳答案

你错过了 run这是运行其他 pry 命令所必需的:

Pry::Commands.block_command 'fifty', 'List the last fifty inputs' do |x|
run 'hist --tail=50 -a'
end

关于ruby - 尝试在自定义 pry 命令中运行 pry 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52611949/

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