Ruby gem naming conventions Ruby gem naming conventions ruby ruby

Ruby gem naming conventions


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:


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.)


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.