I’ve built a custom Ruby gem. Call it MyGem, then file lib/innermodule.rb contains:
module MyGem
module InnerModule
def self.foo(); puts "Hello world!"; end
end
end
To reference this from another gem that’s in development I have to do:
require 'mygem'
require 'innermodule'
Is this normal behaviour, or is there a problem with the gemspec for MyGem?
I don’t know if this is necessarily a problem with your gemspec since you usually just specify what files to include in a gem. Gemspecs don’t really have anything to do with the way a gem gets required into another app.
It sounds like a problem with the way your gem is built/packaged specifically with regards to naming and file path conventions.
There are some common conventions that are usually followed for building gems and what I referenced above
http://guides.rubygems.org/patterns/ has a good overview.
Basically, you usually want to create a single file (usually the name of your gem) that sits in the “lib” directory. In this case, “lib/mygem.rb” would have individual requires for the internal dependencies of the gem.
Then to include the gem (as well as the inner module) in any other app, you could just do