Stop rails console from printing out the object at the end of a loop

不问归期 提交于 2019-12-04 07:35:38

问题


If I, say, loop through all the instances of a given model and output something from each, at the end, irb will still print the entire object.

If the object ends up taking hundreds of lines, it'll be a long way up before I see what I was actually looking for. Is there a way to disable this in the rails console?


回答1:


If you don't want to disable the echo in general you could also call multiple expressions in one command line. Only the last expression's output will be displayed.

big_result(input); 0



回答2:


Call conf.echo = false and it will not print the return value. This works for any irb session, not just Rails console.

In case you want to make it permanent, add it to your irb config.

echo 'IRB.conf[:ECHO] = false' >> $HOME/.irbrc



回答3:


To temporarily stop the console from printing the return values you can issue a nil statement at the end of your loop or function, but before pressing the return.

record.each do |r|
  puts r.properties
end; nil

Or it can be a number too, if you want to reduce typing. But it can be confusing in scenarios, which I can't think of.

record.each do |r|
  puts r.properties
end; 0


来源:https://stackoverflow.com/questions/13284277/stop-rails-console-from-printing-out-the-object-at-the-end-of-a-loop

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