Avoids unnecessary conflicts when a previously non-keg_only formula is in the way by prioritizing keg_only before non-keg_only formulae. This change is motivated by the upgrade of gnupg 2.0 to 2.1, since the latter no longer depends on the gpg-agent formula, which, even if made keg_only, still causes the link step to fail for 2.1, as gpg-agent's non-keg version won't have been upgraded to the keg_only version at that point (alphabetically gnupg precedes gpg-agent).
Homebrew's Formula API
This is the (partially) documented public API for Homebrew.
The main class you should look at is the {Formula} class (and classes linked from there). That's the class that's used to create Homebrew formulae (i.e. package descriptions). Assume anything else you stumble upon is private.
You may also find the Formula Cookbook and Ruby Style Guide helpful in creating formulae.
Good luck!