Blog

Jan
23
Suppressing IRB Output
by Dylan Stamat | Snippet

When in IRB or Console, you can often get back large blocks of output even when you didn’t want it. This happens often when inspecting your database through Console, working with SOAP responses, XML parsing, etc. You could always scroll up in your terminals buffer to find the results you were looking for, or, you can forcefully “suppress” the IRB output.


# using each
>> User.all.each { |u| u.save }
=> [#

# using map
>> User.all.map { |u| u.save }
=> [true, true, true .... etc, etc, etc]

# suppressing
>> User.all.map { |u| u.save }; 0
=> 0

Just add a semi-colon followed by an object.

Finding this out after years of scrolling resulted in a large ‘facepalm’ on my part ;)

3 Comments
James Moline
January 24, 2009

Seriously, thanks for this post. It seems like I’ve been looking forever to find a way to get rid of this kind of data dump.

January 24, 2009

Ahh I remember the day I figured this one out. Changed my world. I do ‘and nil’.

August 10, 2009

Oh wow. So intuitive :-/
Been looking for a solution for months. Surely this must be a FAQ when using the console. My .find(:all)’s are suddenly much more pleasant!

Cheers.