IRB return trick

Ruby — Dillon @ 10:13 pm

Irb, like ruby and many other languages, returns things to the left. When you say:

x = 5

5 gets sent to x and x gets sent to the console or to the bit bucket if nothing is watching for it. Irb with Ruby will tell you this explicitly which is great for debugging and developing.

>> x = 5
=> 5

But sometimes it’s annoying. Like when you have a massive array of objects and you’re iterating through them. A quick trick is to add another meaningless return on the end like this:

>> x = 5; 1
=> 1

If x=5 was a huge database result set or a large array, it’d be hard to read. But 1 is easy to ignore.

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 SQUARISM | powered by WordPress with Barecity