Skip to content

Commit

Permalink
stop some errors, make h3's not look stupid, start on patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 30, 2011
1 parent 0ba8acb commit ab5b273
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion make-your-own-gem.md
Expand Up @@ -393,7 +393,7 @@ It's green! Well, depending on your shell colors. For more great examples, the b
Documenting your code
---------------------

By default most gems use [RDoc] to generate docs. There's a lot of
By default most gems use RDoc to generate docs. There's a lot of
[great](http://handyrailstips.com/tips/12-documenting-your-application-or-plugin-using-rdoc)
[tutorials](http://docs.seattlerb.org/rdoc/RDoc/Markup.html) for learning how
to mark up your code with RDoc. Here's a simple example:
Expand Down
94 changes: 94 additions & 0 deletions patterns.md
Expand Up @@ -9,3 +9,97 @@ Patterns
========

Common practices to make your gem users and other developers' lives easier.

* [Consistent naming](#consistent-naming)
* [Semantic versioning](#semantic-versioning)
* [Declaring dependencies](#declaring-dependencies)
* [Loading code](#loading-code)
* [Other files](#other-files)
* [Requiring 'rubygems'](#requiring-rubygems)
* [Prerelease gems](#prerelease-gems)

<a id="consistent-naming"> </a>
Consistent naming
-----------------

> There are only two hard things in Computer Science: cache invalidation and naming things.
> -[Phil Karlton](http://martinfowler.com/bliki/TwoHardThings.html)
### File names

Be consistent with how your gem files in `lib` and `bin` are named. The
[hola](http://github.com/qrush/hola) gem from the [make your own
gem](/make-your-own-gem) guide is a great example:

% tree
.
├── Rakefile
├── bin
│   └── hola
├── hola.gemspec
├── lib
│   ├── hola
│   │   └── translator.rb
│   └── hola.rb
└── test
└── test_hola.rb

The executable and the primary file in `lib` are named the same. A developer
can easily jump in and call `require 'hola'` with no problems.

### Naming your gem

Naming your gem is important. Before you pick a name for your gem, please do a
quick search on [RubyGems.org](http://rubygems.org) or
[GitHub](http://github.com/search) to see if someone else has taken it. Once
you have a name, we have a [few
guidelines](http://blog.segment7.net/2010/11/15/how-to-name-gems) on how
to name them, paraphrased below.

### Use underscores for spaces

Such as [newrelic_rpm](http://rubygems.org/gems/newrelic_rpm) or
[factory_girl](http://rubygems.org/gems/factory_girl). This matches the file in
your gem that your users will `require` along with the name. For example,
`gem install my_gem` will match `require 'my_gem'`

### Use dashes for extensions

Adding new functionality to an existing gem? Use a dash. Some examples include
[net-http-persistent](https://rubygems.org/gems/net-http-persistent) and
[autotest-growl](https://rubygems.org/gems/net-http-persistent).

Usually this implies that you'll have to `require` into their directory tree
as well. For example, `gem install net-http-persistent` becomes `require
'net/http/persistent'`.

### Don't use UPPERCASE

These gems cause problems for gem users on OSX and Windows, which use
case-insensitive filesystems. Plus, when installing gems it's confusing. Do I
run `gem install Hola` or `gem install hola` ? Just keep it lowercase.

<a id="semantic-versioning"> </a>
Semantic versioning
-------------------

<a id="declaring-dependencies"> </a>
Declaring dependencies
----------------------

<a id="loading-code"> </a>
Loading code
------------

<a id="other-files"> </a>
Other files
-----------

<a id="requiring-rubygems"> </a>
Requiring `'rubygems'`
--------------------

<a id="prerelease-gems"> </a>
Prerelease gems
--------------------

2 changes: 1 addition & 1 deletion resources.md
Expand Up @@ -37,5 +37,5 @@ Patterns
--------

* [Gem Packaging: Best Practices](http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices)
* [Gem Best Practice](http://blog.nofail.de/2010/11/gem-best-practice/)
* [Rubygems Good Practice](http://yehudakatz.com/2009/07/24/rubygems-good-practice/)
* [Gem Development Best Practices](http://blog.carbonfive.com/2011/01/22/gem-development-best-practices/)
2 changes: 2 additions & 0 deletions stylesheets/screen.css
Expand Up @@ -689,6 +689,8 @@ body.home {
font-weight: bold;
margin: 25px 0;
clear: both; }
#container #content h3 {
font-size: 16px; }
#container #content p {
margin: 1em 0; }
#container #content pre {
Expand Down
4 changes: 4 additions & 0 deletions stylesheets/screen.scss
Expand Up @@ -164,6 +164,10 @@ body.home {
clear: both;
}

h3 {
font-size: 16px;
}

p {
margin: 1em 0;
}
Expand Down

0 comments on commit ab5b273

Please sign in to comment.