由于某些原因,当我使用binding.pry
设置断点时,程序最终会停在一个完全不同的(并且看起来像外星人!)的位置。我做错了吗?
Gemfile(缩写)
gem "rails", "~> 4.1"
gem "pry"
gem "pry-rails"
gem "pry-doc"
gem "pry-stack_explorer"
gem "pry-byebug"
方案
断点:
class SomeController < Application controller
before_filter :filter
...
def filter
assignment = SkillAssignment.where(day: selected_date).first
if assignment
@day_skill = assignment.skill
@day_description = @day_skill.description
end
binding.pry
end
end
我降落的地方(使用show-source
):
[1] pry(ActiveSupport::Callbacks::Filters::Before)> show-source
From: /home/yan-foto/workspaces/my-app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb @ line 156:
Owner: #<Class:ActiveSupport::Callbacks::Filters::Before>
Visibility: private
Number of lines: 16
def self.halting(next_callback, user_callback, halted_lambda, filter)
lambda { |env|
target = env.target
value = env.value
halted = env.halted
unless halted
result = user_callback.call target, value
env.halted = halted_lambda.call(target, result)
if env.halted
target.send :halted_callback_hook, filter
end
end
next_callback.call env
}
end
答案 0 :(得分:2)
感谢@Manuel和@Anthony我现在知道这个问题是由bug中的pry-byebug
引起的。不幸的是,这似乎不会在mentioned by the developer in GitHub:
目前的情况是我几乎没有使用过撬棍,所以我觉得 我没有使用mantain软件的动力不足。 :(
如果你想在结尾处有binding.pry
,一个简单的解决方法就是写下这样的东西:
def myMethod
# magic
binding.pry
1 + 1
end