Pry: show me the stack

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

I want to know how I got here, who called me, who called them, etc. But strangely I do not see this command. Somebody knows?

+68
ruby-on-rails pry
Mar 08 '13 at 20:54
source share
4 answers

Use the pry-stack_explorer plugin , it allows you to move up and down the call stack (using up and down ), display a still image (with show-stack ), etc.:

see here:

 Frame number: 0/64 From: /Users/johnmair/ruby/rails_projects/personal_site/app/controllers/posts_controller.rb @ line 7 PostsController#index: 5: def index 6: @posts = Post.all => 7: binding.pry 8: end [1] pry(#<PostsController>)> show-stack Showing all accessible frames in stack (65 in total): -- => #0 index <PostsController#index()> #1 [method] send_action <ActionController::ImplicitRender#send_action(method, *args)> #2 [method] process_action <AbstractController::Base#process_action(method_name, *args)> #3 [method] process_action <ActionController::Rendering#process_action(*arg1)> <... clipped ...> [2] pry(#<PostsController>)> up Frame number: 1/64 Frame type: method From: /Users/johnmair/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb @ line 4 ActionController::ImplicitRender#send_action: 3: def send_action(method, *args) => 4: ret = super 5: default_render unless response_body 6: ret 7: end [3] pry(#<PostsController>)> 
+40
Mar 09 '13 at 2:09
source share

There is pry-backtrace that show backtracking for a Pry session.

There is also wtf? . Which shows the return line of the last exception. Add more question marks to see more backtrack or exclamation mark to see it all.

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

+72
Mar 08 '13 at 21:25
source share

To do this without any pry plugins (I had problems with pry-stack_explorer), just look at caller .

I'm really looking for my project name to filter out all the unnecessary elements of the rail stack. For example, if my project name is archie , I would use:

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

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

Shorter way:

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

Which works just as well.

+62
Feb 07 '14 at 5:49
source share

You can use the invocation method that is already defined inside the gem library. The return value of this method will be an array. So you can use array methods to search in this group of strings

It is also useful to use powerful tracing below. https://github.com/pry/pry-stack_explorer

+1
Dec 23 '14 at 13:33
source share



All Articles