Pry: show me the stack

Using Pry in Rails, when I hit a breakpoint in the code binding.pry

I want to know how I got here, who called me, who called them, etc. But oddly I don't see that command. Does anyone know?


Solution 1:

To do this without any pry plugins (I was having troubles with pry-stack_explorer), just look at caller.

I actually look for my project name to filter out all the irrelevant rails stack items. For example, if my project name were archie I'd use:

caller.select {|line| line.include? "archie" }

Which gives me the stack trace I'm looking for.

A shorter way would be:

caller.select {|x| x["archie"] }

Which works just as well.

Solution 2:

There is pry-backtrace which show's the backtrace for the Pry session.

There is also wtf?. Which show's the backtrace of the most recent exception. Add more question marks to view more of the backtrace or an exclamation mark to see it all.

Type help in pry to see all the other commands :)