Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

ruby - Pry is not a module

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...