【问题标题】:Ruby (bundler) How to automatically require PryRuby(捆绑器)如何自动要求 Pry
【发布时间】:2017-11-23 08:20:18
【问题描述】:

给定一个包含以下内容的 Gemfile:

source 'https://rubygems.org'

gem 'pry'

还有一个 ruby​​ 文件,其中包含:

require 'bundler/setup'

# NOT using this line:
# require 'pry'

binding.pry

我收到此错误:

enter code hereundefined 方法pry' for #<Binding:0x00007f846f053bb0> (NoMethodError)

我知道我可以轻松地在我的文件中添加require 'pry',但我真的不想在调试文件时这样做。

另外,我凭直觉相信bundler/setup 会自动要求我在 Gemfile 中定义的 ruby​​gems。

您能解释一下如何在我的 Gemfile 中自动要求该文件吗?

【问题讨论】:

    标签: ruby bundler pry binding.pry


    【解决方案1】:

    诀窍是在require 'bundler/setup' 之后使用Bundler.require(:default) - 因为后者只是设置加载路径。见http://bundler.io/v1.16/guides/bundler_setup.html

    【讨论】:

    • 感谢您提供准确、简单的回答!
    猜你喜欢
    • 1970-01-01
    • 2013-06-16
    • 2020-10-27
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    • 2016-02-21
    • 2019-06-05
    • 1970-01-01
    相关资源
    最近更新 更多