Pry: show me the stack

pitosalas picture pitosalas · Mar 8, 2013 · Viewed 47.9k times · Source

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?

Answer

Paul Oliver picture Paul Oliver · Feb 7, 2014

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.