Stop the rail console from printing the object at the end of the cycle

If I, say, iterate over all instances of this model and issue something from each, in the end, irb will still print the entire object.

If an object ends up accepting hundreds of lines, it will be a long way to go before I see what I was really looking for. Is there any way to disable this in the rails console?

+52
ruby ruby-on-rails console irb
Nov 08 '12 at 7:16
source share
3 answers

If you do not want to disable echo in general, you can also invoke multiple expressions on the same command line. Only the last output of the expression is displayed.

big_result(input); 0 
+71
Nov 08
source share

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

If you want to make it permanent, add it to the irb configuration.

 echo 'IRB.conf[:ECHO] = false' >> $HOME/.irbrc 
+72
Nov 08 '12 at 7:20
source share

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

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

Or it could be a number if you want to reduce text input. But this can be confusing in scenarios that I can't think of.

 record.each do |r| puts r.properties end; 0 
+24
Nov 27 '12 at 11:27
source share



All Articles