You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-23Lines changed: 32 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,43 +140,52 @@ You can generate a PDF or an HTML copy of this guide using
140
140
end
141
141
```
142
142
143
-
* put multi when conditions on separate lines
143
+
* put multiple when conditions on separate lines
144
+
particularly where the conditions form long, complicated lines
144
145
145
146
```Ruby
146
147
# good
147
148
148
149
case token
149
-
when :star_op
150
-
stack.pop * stack.pop
151
-
when :slash_op
152
-
stack.pop / stack.pop
153
-
when :minus_op
154
-
also_calculate_that
155
-
stack.pop - stack.pop
156
-
when :plus_op,
157
-
:plus_plus_op
158
-
stack.pop + stack.pop
159
-
when :int_literal
160
-
token.value
161
-
end
150
+
when :star_op
151
+
stack.pop * stack.pop
152
+
when :slash_op
153
+
stack.pop / stack.pop
154
+
when :minus_op, :minus_minus_op
155
+
also_calculate_that
156
+
stack.pop - stack.pop
157
+
when MyModule::SomeDomain::BETA_USERS,
158
+
MyModule::SomeDomain::INTERNAL_RELEASE
159
+
stack.pop + stack.pop
160
+
when :int_literal,
161
+
:some_complicate_explicit_name,
162
+
:graduate_borrowers_with_arms,
163
+
:str_interpolated
164
+
token.value
165
+
end
162
166
```
163
167
164
-
which reads better than
168
+
Though better control of primary domain references should be exercised, this style offers a solution for some 'in the wild' situations. Itreads better than:
165
169
166
170
```Ruby
167
171
# bad
168
172
169
173
case token
170
-
when :star_op
171
-
stack.pop * stack.pop
172
-
when :plus_op, :plus_plus_op
173
-
stack.pop + stack.pop
174
-
when :int_literal, :str_literal, :str_interpolated
175
-
token.value
176
-
end
174
+
when :star_op
175
+
stack.pop * stack.pop
176
+
when :slash_op
177
+
stack.pop / stack.pop
178
+
when :minus_op, :minus_minus_op
179
+
also_calculate_that
180
+
stack.pop - stack.pop
181
+
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
182
+
stack.pop + stack.pop
183
+
when :int_literal, :some_complicate_explicit_name, :graduate_borrowers_with_arms, :str_interpolated
184
+
token.value
185
+
end
177
186
```
178
187
179
-
Where the'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated
188
+
The'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated
180
189
181
190
182
191
*Use empty lines between `def`s and to break up a method into logical
0 commit comments