Ruby : How to write a gem? [closed]

2020-01-27 08:31发布

I'd like to write a package for Ruby and make it available as a gem.
What are the tools, steps and pitfalls ?
Are there any good tutorials, screencasts, etc., which helped you learning how to do it ?

标签: ruby rubygems
3条回答
何必那么认真
2楼-- · 2020-01-27 09:14

Rubygems.org's Guides is one of the best resources for writing your own gem.

If you're using Bundler in your app, you might want to look at Ryan Bigg's guide to Developing a RubyGem using Bundler and the Railscast on creating gems with Bundler.

If you're interested in tools to help you write gems:

Some tutorials/guides:

查看更多
爷的心禁止访问
3楼-- · 2020-01-27 09:15

You need not start writing a gem, just write some code, write some tests, use it however you want, and once you are happy with it, use gem this to generate the relevant Rakefile.

It helps if you stick to the approaches other gems take (have a lib directory, avoid naming files in ways that could clash with other gems, write some tests if you can, have a readme), but it's not necessary.

Once you have something you want to share, put it on github and push it to gemcutter.

Don't over think it, don't use hoe or other overkill tools, have fun, don't to anything I wouldn't do.

查看更多
老娘就宠你
4楼-- · 2020-01-27 09:22

This is how I usually create and release Gems:

  1. Sign-up for https://github.com
  2. Sign-up for https://rubygems.org
  3. $ gem install ore rubygems-tasks rdoc rspec
  4. $ mine awesome_gem
  5. cd awesome_gem/ and edit the README.rdoc and awesome_gem.gemspec, write code in lib/awesome_gem/ and adding RSpec tests in specs/.
  6. when you're ready to release, update the ChangeLog.rdoc file, run rake spec and rake rerdoc, open up html/index.html and double-check for any typos.
  7. rake release
  8. (Optional) submit a link and explanation of your new awesome gem to http://rubyflow.com

Sit back and bask in the glory of your first Gem. :)

查看更多
登录 后发表回答