使用 RubyMine 新建 gem 工程后,运行 helloworld 程序报错,错误信息如下:
"D:\Program Files\Ruby24-x64\bin\ruby.exe" -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) D:/rubymine_projects/helloworld/lib/helloworld.rb D:/Program Files/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- helloworld/version (LoadError) from D:/Program Files/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require' from D:/rubymine_projects/helloworld/lib/helloworld.rb:1:in `<top (required)>' from -e:1:in `load' from -e:1:in `<main>' Process finished with exit code 1
原因是 helloworld.rb 文件中使用了 require
关键字引用了相对路径:
require "helloworld/version" module Helloworld # Your code goes here... puts "hello"; end
将 require
修改为 require_relative
后,问题解决。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于