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
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,6 +326,54 @@ Translations of the guide are available in the following languages:
326
326
end
327
327
```
328
328
329
+
* <a name="multi-condition-case-when"></a>
330
+
Put multiple when conditions on separate lines.
331
+
Particularly where the conditions form long, complicated lines.
332
+
<sup>[[link](#multi-condition-case-when)]</sup>
333
+
334
+
```Ruby
335
+
# good
336
+
337
+
case token
338
+
when :star_op
339
+
stack.pop * stack.pop
340
+
when :minus_op, :minus_minus_op
341
+
also_calculate_that
342
+
stack.pop - stack.pop
343
+
when MyModule::SomeDomain::BETA_USERS,
344
+
MyModule::SomeDomain::INTERNAL_RELEASE
345
+
stack.pop + stack.pop
346
+
when :int_literal,
347
+
:some_complicate_explicit_name,
348
+
:graduate_borrowers_with_arms,
349
+
:str_interpolated
350
+
token.value
351
+
end
352
+
```
353
+
354
+
Though better control of primary domain references should be exercised, this style offers a solution for some 'in the wild' situations. It reads better than:
355
+
356
+
```Ruby
357
+
# bad
358
+
359
+
case token
360
+
when :star_op
361
+
stack.pop * stack.pop
362
+
when :slash_op
363
+
stack.pop / stack.pop
364
+
when :minus_op, :minus_minus_op
365
+
also_calculate_that
366
+
stack.pop - stack.pop
367
+
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
368
+
stack.pop + stack.pop
369
+
when :int_literal, :some_complicate_explicit_name, :graduate_borrowers_with_arms, :str_interpolated
370
+
token.value
371
+
end
372
+
```
373
+
374
+
The 'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated
375
+
376
+
329
377
* <a name="indent-conditional-assignment"></a>
330
378
When assigning the result of a conditional expression to a variable,
0 commit comments