撬:告诉我堆栈

pit*_*las 89 ruby-on-rails pry

使用Pry in Rails,当我在代码binding.pry中遇到断点时

我想知道我是怎么来到这里的,谁打电话给我,打电话给他们等等.但奇怪的是我没有看到那个命令.有人知道吗?

Pau*_*ver 120

要做到这一点,没有任何撬插件(我有pry-stack_explorer的麻烦),看看caller.

我实际上寻找我的项目名称来过滤掉所有不相关的rails堆栈项目.例如,如果我的项目名称是archie我使用的:

caller.select {|line| line.include? "archie" }
Run Code Online (Sandbox Code Playgroud)

这给了我正在寻找的堆栈跟踪.

一个较短的方法是:

caller.select {|x| x["archie"] }
Run Code Online (Sandbox Code Playgroud)

哪个也适用.

  • 完善.我在tmux中添加了一个key-combo来输入它(bind'B'send-keys'... ^ M'),使用"reject"代替它,因此它更通用:```caller.reject {| x | x ["vendor/bundle"] || x ["/.rbenv/versions /"]}``` (5认同)
  • 对于Ruby社区来说,真正的形式,唯一有用的答案是埋在建议下安装一些插件. (3认同)
  • 这个答案值得这么多赞成.是的,你可以在撬上安装更多东西.但是你也可以使用ruby现有的语言功能来获得差不多(当然足以回答OP的问题!) (3认同)
  • 这个答案应该是正确的,因为它不需要额外的插件! (3认同)

gef*_*gef 81

有一个pry-backtrace显示了Pry会话的回溯.

还有wtf?.哪个节目是最近一次异常的回溯.添加更多问号以查看更多回溯或感叹号以查看全部内容.

在pry中键入help以查看所有其他命令:)

  • 但事实是有时你不使用所有这些功能:) (7认同)

hor*_*guy 47

使用pry-stack_explorer插件,它允许您在调用堆栈中上下移动(使用updown),显示callstack(with show-stack),依此类推:

看这里:

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>)> 
Run Code Online (Sandbox Code Playgroud)