如何在Pry中自定义Ruby命令的返回输出

时间:2012-03-30 18:19:46

标签: ruby irb read-eval-print-loop pry

我能够使用〜/ .pryrc中的Pry.config.prompt设置自定义Pry的提示,以便让孩子们更容易使用Pry。现在我想摆脱返回输出:

Enter Ruby code> puts 'hello'
hello
=> nil
Enter Ruby code> 

=> nil对于刚刚学习编程的孩子来说很困惑。我可以在Pry中抑制返回值输出吗?

1 个答案:

答案 0 :(得分:5)

有几种方法可以做到这一点。将;添加到每行的末尾,或将默认Pry.config.print替换为您自己的proc。例如,添加类似

的内容
Pry.config.print = Proc.new { |output, value| }

到你的~/.pryrc就可以了。