Reputation: 20815
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?
Upvotes: 42
Views: 7726
Reputation: 16274
The dashed version is for extensions on other frameworks, like rspec-rails
and 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 named FooBar
. If that gem should have a rails extension which ships as a different gem, it should be called foo_bar-rails
and the module should be called FooBar::Rails
and it should be required as require "foo_bar/rails"
This convention is also what Bundler tries to require.
Admittedly, this convention is not always followed. jquery_rails
should actually be jquery-rails
and factory_girl_rails
should be called factory_girl-rails
. But hey, not everything is perfect.
RubyGems convention docs:
Upvotes: 70
Reputation: 1101
Turns out that this is answered pretty clearly and succinctly in the rubygems docs: http://guides.rubygems.org/name-your-gem/
(This may be a recent doc addition because I recall searching for this info in the past and not finding it.)
Upvotes: 5
Reputation: 38772
In a recommendation of @svenfuchs:
https://twitter.com/svenfuchs/status/135773593526206464
But it's true that I still see non-coherence behaviors like:
gem 'my_gem`, :require => 'my-gem'
https://twitter.com/#!/svenfuchs/status/135784542819713024
Upvotes: 4
Reputation: 211560
The one advantage is the convention of collapsing foo_bar
into module or class FooBar
as far as autoloaders go. foo-bar
doesn't have a default equivalent.
Generally the underscore version is preferable from a require
perspective, but the dashed version does come across as more readable so it tends to get used often.
Upvotes: 4