Michael Anhari

Grabbing the last result in common Rails debuggers

A top down view of an unplugged mechanical keyboard

When working in Ruby debuggers like pry, byebug, or irb you might want to grab the value for your last command but you forgot to store it to a variable.

Have no fear! The value returned by the last command always gets stored in an underscore variable _:

> Executing task: bin/rails console <

Running via Spring preloader in process 3997
Loading development environment (Rails 6.1.4)
bestreads-development> Book.count
   (2.1ms)  SELECT COUNT(*) FROM "books"
  => 10201
bestreads-development> _
  => 10201

Newsletter

I'm working on sending out a weekly newsletter. I'll make it as easy as possible to unsubscribe at any time.