Pry将带有前导.
的命令解释为系统命令,并将其传递给shell。但是,这使我无法使用具有前导.
的行执行代码块,这在我的代码中非常频繁。
在IRB中,下面的内容工作正常:
2.2.3 :001 > begin
2.2.3 :002 > "hello world"
2.2.3 :003?> .split(" ")
2.2.3 :004?> .map(&:upcase)
2.2.3 :005?> end
=> ["HELLO", "WORLD"]
然而,在Pry中:
[6] pry(#<MailFetcherService>)> begin
[6] pry(#<MailFetcherService>)* "hello world"
[6] pry(#<MailFetcherService>)* .split(" ")
sh: -c: line 0: syntax error near unexpected token `" "'
sh: -c: line 0: `split(" ")'
Error: there was a problem executing system command: split(" ")
有办法解决这个问题吗?我对以下任何一个都没问题:
.
解释为系统命令。.
用于系统命令答案 0 :(得分:0)
如Pry's internal wiki所述,您有两种选择:
config.command_prefix
属性(默认为空字符串""
),这样就可以在需要使用系统命令时添加新的command_prefix
。 / LI>
醇>
#2的例子:
pry(main)> Pry.config.command_prefix = "%"
=> "%"
pry(main)> ls -l
NameError: undefined local variable or method `l' for main:Object
from (pry):2:in `<main>'
pry(main)> %ls
locals: _ _ex_ _pry_ _in_ _out_ _file_ _dir_
pry(main)>