我正在尝试定制我的Pry (使用Pry已经有一段时间了,但这是我第一次尝试创建命令)。我想要创建一个自定义命令,它将从我的历史记录中获取最后的50个项目,我正在构建它,如下所示:
Pry::Commands.block_command "fifty", "List the last fifty inputs" do
hist --tail=50 -a
end一旦这在我的.pryrc文件中,它确实显示了我是否做了‘帮助50’,但如果我试图运行命令,我得到以下信息:
NameError: undefined local variable or method `a' for #<#<Class:0x007f8a1ee49aa8>:0x007f8a1e873ed0>我的猜测是,命令在执行块中的作用域有一些问题,但是我对撬文档的搜索并没有给我任何关于如何继续的想法。其他不尝试复制Pry命令的命令,如示例中的命令
Pry::Commands.block_command "hello", "Say hello to three people" do |x, y, z|
output.puts "hello there #{x}, #{y}, and #{z}!"
end工作得很好。如有任何意见,我们将不胜感激。
发布于 2018-10-03 01:36:00
您缺少了运行其他run命令所需的pry:
Pry::Commands.block_command 'fifty', 'List the last fifty inputs' do |x|
run 'hist --tail=50 -a'
endhttps://stackoverflow.com/questions/52611949
复制相似问题