Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add some changes from Dan Kubb.

  • Loading branch information...
commit 3a811edd10274e915affbb6b388ae2f1cabf57a7 1 parent acf5f63
Greg Campbell authored

Showing 1 changed file with 34 additions and 19 deletions. Show diff stats Hide diff stats

  1. +34 19 RUBY-STYLE
53 RUBY-STYLE
@@ -20,10 +20,7 @@ when you contribute to my code, please follow these rules:
20 20
21 21 * No spaces after (, [ and before ], ).
22 22
23   -* Use two spaces before statement modifiers (postfix
24   - if/unless/while/until/rescue).
25   -
26   -* Indent when as deep as case.
  23 +* Indent `when` as deep as `case`.
27 24
28 25 * Use an empty line before the return value of a method (unless it
29 26 only has one line), and an empty line between defs.
@@ -35,7 +32,7 @@ when you contribute to my code, please follow these rules:
35 32
36 33 * Keep lines fewer than 80 characters.
37 34
38   -* Avoid trailing whitespace.
  35 +* Strip trailing whitespace.
39 36
40 37
41 38 == Syntax:
@@ -44,9 +41,9 @@ when you contribute to my code, please follow these rules:
44 41
45 42 * Never use for, unless you exactly know why.
46 43
47   -* Never use then.
  44 +* Never use then, except in case statements.
48 45
49   -* Use when x; ... for one-line cases.
  46 +* Use when x then ... for one-line cases.
50 47
51 48 * Use &&/|| for boolean expressions, and/or for control flow. (Rule
52 49 of thumb: If you have to use outer parentheses, you are using the
@@ -61,11 +58,8 @@ when you contribute to my code, please follow these rules:
61 58 x = Math.sin(y)
62 59 array.delete e
63 60
64   -* Prefer {...} over do...end. Multiline {...} is fine: having
65   - different statement endings (} for blocks, end for if/while/...)
66   - makes it easier to see what ends where. But use do...end for
67   - "control flow" and "method definitions" (e.g. in Rakefiles and
68   - certain DSLs.) Avoid do...end when chaining.
  61 +* Use {...} when defining blocks on one line. Use do...end for multiline
  62 + blocks.
69 63
70 64 * Avoid return where not required.
71 65
@@ -111,15 +105,18 @@ when you contribute to my code, please follow these rules:
111 105
112 106 And in general, the first letter of the class name if all objects
113 107 are of that type.
114   -
115   -* Use _ or names prefixed with _ for unused variables.
116   -
117 108 * When using inject with short blocks, name the arguments |a, e|
118 109 (mnemonic: accumulator, element)
119 110
  111 +* Use consistent variable names. Try to keep the variable names close
  112 + to the object class name.
  113 +
  114 +* Use names prefixed with _ for unused variables.
  115 +
120 116 * When defining binary operators, name the argument "other".
121 117
122   -* Prefer map over collect, find over detect, find_all over select,
  118 +=======
  119 +* Prefer map over collect, detect over find, select over find_all,
123 120 size over length.
124 121
125 122
@@ -133,8 +130,6 @@ when you contribute to my code, please follow these rules:
133 130
134 131 == The rest:
135 132
136   -* Write ruby -w safe code.
137   -
138 133 * Avoid hashes-as-optional-parameters. Does the method do too much?
139 134
140 135 * Avoid long methods.
@@ -147,18 +142,38 @@ when you contribute to my code, please follow these rules:
147 142
148 143 * Avoid alias when alias_method will do.
149 144
  145 +* Always freeze objects assigned to constants.
  146 +
150 147 * Use OptionParser for parsing complex command line options and
151 148 ruby -s for trivial command line options.
152 149
153   -* Write for 1.8, but avoid doing things you know that will break in 1.9.
  150 +* Write for 1.9, but avoid doing things you know that will break in 1.8.
154 151
155 152 * Avoid needless metaprogramming.
156 153
  154 +* Only give a method one purpose for existing. If you pass in a boolean
  155 + to a method, what you're saying is that this method has two different
  156 + behaviours. Just split it into two single purpose methods. If you have
  157 + to use the words "AND" or "OR" to describe what the method does it
  158 + probably does too much.
  159 +
  160 +* If sections of a method are logically separate by blank lines, then
  161 + that's probably a sign that those sections should be split into separate
  162 + methods.
  163 +
  164 +* Try to keep methods at no more than 10 lines long, and preferably
  165 + 5 or less.
157 166
158 167 == General:
159 168
160 169 * Code in a functional way, avoid mutation when it makes sense.
161 170
  171 +* Try to have methods either return the state of the object and have
  172 + no side effects, or return self and have side effects. This is
  173 + otherwise known as Command-query separation (CQS):
  174 +
  175 + http://en.wikipedia.org/wiki/Command-query_separation
  176 +
162 177 * Do not mutate arguments unless that is the purpose of the method.
163 178
164 179 * Do not mess around in core classes when writing libraries.

0 comments on commit 3a811ed

Please sign in to comment.
Something went wrong with that request. Please try again.