构造红宝石的现代方式是什么? [英] What is the modern way to structure a ruby gem?
本文介绍了构造红宝石的现代方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
有些帖子我发现有用:
- http://chneukirchen.github.com/rps/
- http://tomayko.com/writings/require -rubygems-antipattern
- http://yehudakatz.com/2009/07/24/rubygems-good-practice/
- http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
-
编辑(2012-01-10):宝石最佳实践的全面指导是 RubyGems指南。我强烈建议现在从这里开始。
总结关键点:$ b
$ b
- 为代码使用基本的
lib / gem.rb
和lib / gem /
结构。 - 将任何可执行文件放入
bin
中,将data
中的任何数据文件放入test
或spec
。 - 不要
require
或依赖加载路径之外的文件。 (VERSION
文件通常似乎生活在宝石中的奇怪位置。) - 不要
require'rubygems'
。 - 请勿篡改
$ LOAD_PATH
。 - 如果您发现自己写了
需要File.join(__ FILE__,'foo','bar')
,那么您就错了。
Has much changed with the release of Bundler? Is there a template that can be used as a base? What are the best practices?
解决方案
Some posts that I have found useful:
- http://chneukirchen.github.com/rps/
- http://tomayko.com/writings/require-rubygems-antipattern
- http://yehudakatz.com/2009/07/24/rubygems-good-practice/
- http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
Edit (2012-01-10): An excellent all-around guide to gem best practices is RubyGems Guides. I would highly recommend starting here now.
To summarize the key points:
- Use the basic
lib/gem.rb
andlib/gem/
structure for code. - Put any executables in
bin
, any data files indata
and tests intest
orspec
. - Don't
require
or depend upon files outside of the load path. (VERSION
files often seem to live in odd places in gems.) - Do not
require 'rubygems'
. - Do not tamper with the
$LOAD_PATH
. - If you find yourself writing
require File.join(__FILE__, 'foo', 'bar')
, you're doing it wrong.
这篇关于构造红宝石的现代方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文