Name: style-guide
Owner: Simpleweb
Description: null
Created: 2012-03-28 08:37:19.0
Updated: 2013-01-08 10:49:42.0
Pushed: 2012-03-18 11:48:36.0
Size: 66
Language: null
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Choose a Github Issue.
Create a local feature branch off of master for development.
git checkout master
git pull
git checkout -b 123-feature-xyz
Do work in your feature branch and commit the changes.
git add -A
git status
git commit
Write a good commit message.
[#123] Summary of changes under 50 characters
* More information about commit (under 72 characters)
* More information about commit (under 72 characters)
A good commit message:
Share your feature branch
git push origin [branch]
Rebase frequently to incorporate upstream changes.
git checkout master
git pull
git checkout [branch]
git rebase master
<resolve conflicts>
Interactive rebase (squash) your commits (if necessary).
git rebase -i master
Merge your branch back to master and push your changes.
git checkout master
git diff --stat master [branch]
git merge [branch] --ff-only
git push origin master
Delete your remote feature branch.
git push origin :[branch]
Delete your local feature branch.
git branch -d [branch]
Close Github Issue.
(
, [
. No spaces before ]
, )
.XmlHttpRequest
not XMLHTTPRequest
),
even if the acronym is the entire name (class Html
not class HTML
).{
and before }
.\n
).%q
, %Q
, %x
, %s
, and %W
..rvmrc
s, file watchers, debuggers.x = Math.sin(y)
array.delete e
boolean ? true : false
). Use multi-line if
instead to emphasize code branches.unless
with else
.map
over collect
and reduce
over inject
due to symmetry and
familarity with mapping and reducing in other technologies.detect
over find
and find_all
over select
to avoid confusion
with ActiveRecord and keep select
/reject
symmetry._
for unused block parameters.hash.map { |_, v| v + 1 }
%()
for single-line strings needing interpolation and double-quotes.%w()
over ['', '']
for an array of words.&&
and ||
for boolean expressions.||=
freely.{...}
over do..end
for single-line blocks.!
suffix for dangerous methods (modifies self
).?
suffix for predicate methods (return a boolean).CamelCase
for classes and modules, snake_case
for variables and
methods, SCREAMING_SNAKE_CASE
for constants.def
with parentheses when there are arguments.do..end
over {...}
for multi-line blocks./(?:first|second)/
over /(first|second)/
when you don't need the
captured group.private
over protected
to indicate scope.def self.method
over def Class.method
or class << self
.Set
over Array
for arrays with unique elements. The lookup is faster.unless boolean?
instead of if !boolean?
.:except
option in routes.member
and collection
routes.private
methods to their own object.where('inviter_id is not null')
) outside of
models.config.action_mailer.raise_delivery_errors = true
in the development
environment.config/initializers
.db/schema.rb
under version control.paperclip.rb
private
methods.private
methods.config/locales
.config.action_mailer.delivery_method = :test
in the test environment._path
over _url
for named routes everywhere except mailer views.def self.method
over the named_scope :method
DSL.I18n.t 'dot.separated.key'
over
I18n.t :key, :scope => [:dot, :separated]
.has_and_belongs_to_many
if all you need is a join table. Start simple.t '.title'
.belongs_to
relationships between resources.ActionMailer
for the app. Name it Mailer
.render 'partial'
syntax over render :partial => 'partial'
.:only
option to explicitly state exposed routes.its
, specify
, subject
, and other DSLs. Prefer explicitness and
consistency.it
blocks with 'should'.context
blocks names with 'given' when receiving input. Prefix with
'when' in most other cases.describe
blocks after the method under test. Use self.method
for class methods and method
for instance methods. This matches the method
definition itself.--format documentation
.context
block for each execution path through the method.before
blocks to clearly define the 'setup' phase of the
Four Phase Test.it
block.