I’m creating a ruby gem and I’ve noticed that there doesn’t seem to be (to my knowledge) a naming convention for gems. For example, I’ve seen both:
gem 'foo-bar'
gem 'foo_bar'
Is there some kind of definitive guide/convention for the naming of ruby gems?
The dashed version is for extensions on other frameworks, like
rspec-railsand the underscore is for part of the normal gem name and should be camelcased in your classes.So if you have a gem named
foo_bar, the class/module should be namedFooBar. If that gem should have a rails extension which ships as a different gem, it should be calledfoo_bar-railsand the module should be calledFooBar::Railsand it should be required asrequire "foo_bar/rails"This convention is also what Bundler tries to require.
Admittedly, this convention is not always followed.
jquery_railsshould actually bejquery-railsandfactory_girl_railsshould be calledfactory_girl-rails. But hey, not everything is perfect.RubyGems convention docs: