Suppress IRB output?

Possible duplicate:
Rails console, how to stop return value output?

Consider this session in IRB:

>> for a in 1..5 do ?> puts a >> end 1 2 3 4 5 => 1..5 >> 

How to suppress output => 1..5 ? This is important if I do this in a Rails console session:

 for post in Post.find(:all) do if post.submit_time > Time.now puts "Corrupted post #{post.id} is from the future" end end 

I do not want all messages printed as an array at the end. How can I suppress this conclusion?

I am sure there are other ways to do this, such as find_each or Ruby script, but I'm more interested in this in an interactive session.

+4
source share
3 answers

Just add nil to the end of your command. It does not kill the irb response line, but if you have a large object, this avoids the explosion of the screen.

 1.9.3p194 :036 > for a in 1..5 do; puts a; end; nil 1 2 3 4 5 => nil 
+17
source

This is the basic functionality of IRB. You enter an expression, it prints its value. In this case, the value is 1..5 . Another way out is just a side effect.

However, you can "minimize" the returned (and printed) value. So, instead of a large array of AR fat models, you can return something small.

Try something like this:

 % irb 1.9.3p194 :001 > for a in 1..5 do 1.9.3p194 :002 > puts a 1.9.3p194 :003?> end; nil 1 2 3 4 5 => nil 
+3
source

You can simply add a semicolon ( ; ) to your command, which will actually delay the execution of the command until the next execution, and the IRB will never print the result. This is faster than typing nil , and the side effects are not very noticeable if you just run another command right after.

Quick example:

 irb(main):001:0> def foo; puts 'foo'; end => nil irb(main):002:0> foo foo => nil irb(main):003:0> foo; irb(main):004:0* 42 foo => 42 
+2
source

All Articles