Grabbing the last result in common Rails debuggers
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