Pry: "next" 命令没有像我预期的那样工作

Pry: "next" command don't work as I expected

我正在尝试使用 Pry 进行调试。大多数时候,每当我使用 next 命令跳过下一行时,撬开它似乎是另一帧。例如,看我的代码:

Item.where(dst: "book").each do |book|
    ott = book.ott
    est = extract_es_title(ott) if ott != nil
    web_item = Item.find_by(su: GR_BASE_URL+book.id)
    binding.pry
end

class Item
    include Mongoid::Document
    include Mongoid::Timestamps

    field :su, as: :source_url
    field :ott, as: :other_titles
    field :dst, as: :details_structure
end

如果我 运行 代码,它会在正确的断点处停止。但是,如果我在 Pry 控制台中 运行 next 一次,它会进入堆栈中看起来更深的位置,而不是跳到下一行。这是 Pry 在我 运行 next:

后显示的代码
    645: def yield_document(document, &block)
    646:   doc = document.respond_to?(:_id) ?
    647:     document : Factory.from_db(klass, document, criteria.options[:fields])
    648:   yield(doc)
 => 649:   documents.push(doc) if cacheable?
    650: end

为什么会出现这种行为?我怎样才能跳转到下一个方法行?

提前致谢。

如果要转到each块的下一个迭代。您可以将 binding.pry 移动到循环的开头,每次移动 运行 continue

Item.where(dst: "book").each do |book|
    binding.pry
    ott = book.ott
    est = extract_es_title(ott) if ott != nil
    web_item = Item.find_by(su: GR_BASE_URL+book.id)
end

使用断点:

break 4 然后点击 CTRL-D 或输入 continue 它应该带你到第 4 行。通常 "next line" 被认为是下一行执行,而不是下一行当前文件的行。

来自文档:https://github.com/nixme/pry-debugger