问题描述
好吧,正如@ tim-moore所问,我会在新问题中发布它。
好的,我想用bundle来制作gem。 Pry extension gem要求gem以 pry 开头,如。
我用过:
bundle gem pry-name
但它弄乱了我的文件结构
创建pry-name / pry-name.gemspec
创建pry-name / lib / pry / name.rb
创建pry-name / lib / pry / name / version.rb
您可以看到它创建了 lib / pry 目录。我知道这是宝石的风格来创建这样的结构,但现在我撬不能自动加载这个宝石
从是:
的pry-name.rb
require要求:
'pry-name'#失败,说:Pry不是一个模块
至于我的猜测:
我创建了如下命令:
Pry: :Commands.create_commandname-of-commanddo
#my code goes here
end
,并且,如ruby找到 Pry :: Commands。它希望从 lib 目录不要求Pry gem。 p>
这个错误是什么意思。为什么它不起作用。如何使它工作,记住宝石和撬要求(pry gem以 pry - 开头,当某人使用时,gem将创建另一个目录(ies) 例如: gem pry-name 会使 pry / name )
无论您在新创建的gem中具有模块Pry 的地方,都可以将其更改为: class Pry 。由于 Pry 已经被定义(作为一个类),所以你不能重新定义/重新打开它作为一个模块。
Ok, as @tim-moore asked, I will post it in new question.
Ok, so I wanted to make gem using bundle. Pry extension gem require that gem start with pry- as mentioned here.I used:
bundle gem pry-name
but it messed up my file structure
create pry-name/pry-name.gemspec create pry-name/lib/pry/name.rb create pry-name/lib/pry/name/version.rb
As you can see it created lib/pry directory. I know it's gem's style to created such structure but now I pry cannot load this gem automatically
One solution from my question was:
After I have done this, and build gem, I started pry:This message appear:
require 'pry-name' # Failed, saying: Pry is not a module
As for my guesses:
I'm creating commands writing something like this:
Pry::Commands.create_command "name-of-command" do # my code goes here end
and, as ruby find Pry::Commands. it want require it from lib directory not from Pry gem.
What does this error mean. Why it doesn't work. How make it work keeping in mind gem and pry requirements(pry gem starts with pry- and gem will create another directory(ies) when someone use - for example: gem pry-name will make pry/name)
Everywhere in your newly-created gem where it has module Pry, change it to: class Pry. Since Pry is already defined (as a class), you cannot redefine/reopen it as a module.
这篇关于Pry不是一个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!