Pry is not a module

痴心易碎 提交于 2019-12-14 03:28:07

问题


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:

create pry-name.rb that contain only require 'pry/name'

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)


回答1:


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.



来源:https://stackoverflow.com/questions/19889569/pry-is-not-a-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!