Trick that work in irb and python shell

This irb tip is from Natasha the Robot. Often we forgot to assign an expression to a variable, you could of course use up arrow to retrieve last command and then move all the way to the front, add a variable and equal sign to it, but that is a lot of troubles.

An easy way is just assign a variable to underscore, like this

text = _

Then you have your previous expression assigned to a variable called text. Magical.

What is more surprising is that just found out that this magical trick works the same in python shell! Even more magical.

Leave a Reply

Your email address will not be published. Required fields are marked *