Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 924
dsp_099 Avatar asked Nov 08 '12 07:11

dsp_099


People also ask

How do you escape the console in Rails?

We can exit the Rails console by typing exit.

How to clear irb screen?

On Mac OS X or Linux you can use Ctrl + L to clear the IRB screen. @fanaugen On MacOS, cmd+k will clear all within a terminal tap, if you use tmux to split area of the visual area, ctrl+L will do a better work.

What can you do in Rails console?

The console command lets you interact with your Rails application from the command line. On the underside, bin/rails console uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.

What is GitLab Rails console?

The Rails console. provides a way to interact with your GitLab instance from the command line. The Rails console interacts directly with GitLab. In many cases, there are no handrails to prevent you from permanently modifying, corrupting or destroying production data.


2 Answers

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 
like image 188
aef Avatar answered Oct 03 '22 09:10

aef


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 
like image 32
lulalala Avatar answered Oct 03 '22 09:10

lulalala