gpt4 book ai didi

ruby - 无法加载 'pry' - `require' : cannot load such file -- pry (LoadError)

转载 作者:数据小太阳 更新时间:2023-10-29 08:57:25 24 4
gpt4 key购买 nike

我正在尝试调试一个简单的 ruby​​ 控制台脚本,但在尝试要求 pry 时出现加载错误:

  • 我正在使用 rbenv 来管理环境。
  • 我使用的是 Ruby 版本:2.3.1.
  • 尝试使用 Pry '~> 0.10.4'

/Users/gangelo/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pry (加载错误)

我过去曾在 Rails 应用程序中使用过 Pry 和 Byebug,但从未遇到过此类问题。在寻找解决方案时,我发现大多数问题都与 Gemfile 中不包含 Pry 或 Gem 文件中正确环境中的 Pry gem 不包含有关;我不是这样,我做错了什么?

# /Gemfile
group :development, :test do
gem 'pry', '~> 0.10.4'
end

在我的脚本中:

# /calculator/rpn_calculator_service.rb
module RealPage
module Calculator
# Provides Reverse Polish Notation computation services.
class RPNCalculatorService < CalculatorService
include Helpers::Arrays

def initialize
super RPNInputParser.new
end

def compute(input)
# Load error here :(
require 'pry'; binding.pry
# Code removed for brevity...
end
# Code removed for brevity...
end
end
end

最佳答案

我在尝试运行我的 gem 时收到类似的错误 cars :

/Users/giovanni/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pry (LoadError)
from /Users/giovanni/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/giovanni/.rvm/gems/ruby-2.2.3/gems/cars-0.0.6/bin/cars:3:in `<top (required)>'
from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/cars:23:in `load'
from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/cars:23:in `<main>'
from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /Users/giovanni/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

我推断可能我的 gem 没有安装所以我就运行了:

➜  ~ gem install pry
Fetching: coderay-1.1.2.gem (100%)
Successfully installed coderay-1.1.2
Fetching: method_source-0.9.0.gem (100%)
Successfully installed method_source-0.9.0
Fetching: pry-0.11.3.gem (100%)
Successfully installed pry-0.11.3
3 gems installed

然后像往常一样执行我的 gem

关于ruby - 无法加载 'pry' - `require' : cannot load such file -- pry (LoadError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48137215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com