How to suppress console outputs / irb Rails

I am stuck in a rather strange problem.

I tested some db entries on our production server in the Rails Console, where almost all the commands led to a huge number of o / p lines, which caused the ssh channel to get hung up :(

Is there any way to suppress the console screen / irb?

thank

+75
ruby ruby-on-rails irb
Jan 13 2018-11-11T00:
source share
5 answers

You can add ; nil for all your teams / operators.

Example:

users = User.all; nil 

Actually, irb prints the (return) value of the last statement executed. Thus, in this case, it will print only zero, since nil is the last valid statement executed :)

+154
Jan 13 2018-11-11T00:
source share

Looking for a solution on how to disable irb / console output, I also found the answer on austinruby.com :

silence irb:

 conf.return_format = "" 

default output:

 conf.return_format = "=> %s\n" 

limit for example 512 characters:

 conf.return_format = "=> limited output\n %.512s\n" 
+29
Jan 25 '13 at 8:38
source share

Here add this to your ~ / .irbrc:

 require 'ctx' require 'awesome_print' module IRB class Irb ctx :ap do def output_value() ap(@context.last_value) end end ctx :puts do def output_value() puts(@context.last_value) end end ctx :p do def output_value() p(@context.last_value) end end ctx :quiet do def output_value() end end end end def irb_mode(mode) ctx(mode) { irb } end 

(Note: you must first set the ctx stone, although awesome_print is optional, of course.)

Now that you are on any console using irb, you can do the following:

Normal mode:

 irb(main):001:0> { this:'is a complex object', that:[ { will:'probably'}, { be:'good to read' } ], in:{ some:{ formatted:'way'} } } => {:this=>"is a complex object", :that=>[{:will=>"probably"}, {:be=>"good to read"}], :in=>{:some=>{:formatted=>"way"}}} 

... yep what are you expecting.

awesome_print :

 irb(main):002:0> irb_mode(:ap) irb#1(main):001:0> { this:'is a complex object', that:[ { will:'probably'}, { be:'good to read' } ], in:{ some:{ formatted:'way'} } } => { :this => "is a complex object", :that => [ [0] { :will => "probably" }, [1] { :be => "good to read" } ], :in => { :some => { :formatted => "way" } } } 

... wow, now everything prints amazingly! :)

Quiet mode:

 irb#1(main):002:0> irb_mode(:quiet) irb#1(main):001:0> { this:'is a complex object', that:[ { will:'probably'}, { be:'good to read' } ], in:{ some:{ formatted:'way'} } } irb#1(main):002:0> 

... ahh, no conclusion at all? Nice.

In any case, you can add any mode that you like, and when you finish with this mode, just exit outside or it and you will return to the previous mode.

Hope this was helpful! :)

+9
Jun 08 '13 at 2:05
source share

Suppressive conclusion, in general

Also, depending on your needs, take a look at using quietly or silence_stream to suppress output in general, and not just in irb / console:

 silence_stream(STDOUT) do users = User.all end 

NOTE: quietly will deprecate in Ruby 2.2.0 and will eventually be uninstalled. (Thanks BenMorganIO !)

More information can be found here .

+5
May 11 '14 at
source share

$ irb --simple-prompt --noecho

+2
Jun 03 '14 at 11:44
source share



All Articles