How can I avoid the console output when assigning a value to a variable in Ruby

让人想犯罪 __ 提交于 2019-12-12 10:55:45

问题


Is it possible to escape that effect when assigning to a value:

irb(main):584:0>a = true
=>true
irb(main):584:0>

I have a code that has lots of assignings and when I am trying to test it I can not see the result because of all these returned values:

true
false
true
false
true
true
..

回答1:


You can start the irb or console attaching the --noecho option.

$ irb --noecho
2.0.0p353 :001 > true
2.0.0p353 :002 > 

Otherwise, if the console was started by another process, simply set conf.echo = false

$ irb 
2.0.0p353 :001 > true
 => true 
2.0.0p353 :002 > conf.echo = false
2.0.0p353 :004 > true
2.0.0p353 :005 > 



回答2:


Stick a semi-colon behind the command and it doesn't print, works for both pry and irb

PRY

[1] pry(main)> a = true
=> true
[2] pry(main)> a = true;
[3] pry(main)>

IRB

2.0.0p247 :001 > a = true
 => true
2.0.0p247 :002 > a = true;
2.0.0p247 :003 >


来源:https://stackoverflow.com/questions/20731930/how-can-i-avoid-the-console-output-when-assigning-a-value-to-a-variable-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!