Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Ruby gem naming conventions

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?

question from:https://stackoverflow.com/questions/8958904/ruby-gem-naming-conventions

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

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...