Suppressing IRB Output

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

  1. James Moline
    Posted January 24, 2009 at 12:50 am | Permalink

    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.

  2. Posted January 24, 2009 at 3:15 am | Permalink

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

  3. Posted August 10, 2009 at 11:56 am | Permalink

    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.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">