Reason #134 •
May 14th, 2026
Getting the last value in IRB with _
An incredibly handy feature of IRB is the ability to use _ to access the result of the last evaluated expression. Perfect for when you just executed a long calculation and realized you forgot to assign it to a variable:
Ruby
2 + 2
# => 4
_ * 3
# => 12
earth_radius = 6_371
Math.sqrt(2 * Math::PI * earth_radius**2)
# => 20015.086796020572
circumference = _
# => 20015.086796020572
History
_ has been around since Ruby 1.6.0, released in August 2000.