..flipping the script..

Underscore in IRB

Published March 26, 2012 - 0 Comments

I was watching Play by Play: Aaron Patterson today and saw him use a cool feature of IRB that I never knew existed, the underscore.

Open up an IRB console and paste in the following:

ruby {name: "tenderlove"}

Now type the following in your IRB console:

ruby puts _[:name]

You should see “tenderlove” printed out! The underscore stores the last value from your IRB session. In this case it’s a Hash that you created at the first step. Pretty awesome right?