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
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -326,6 +326,56 @@ 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 :slash_op
341
+
stack.pop / stack.pop
342
+
when :minus_op, :minus_minus_op
343
+
also_calculate_that
344
+
stack.pop - stack.pop
345
+
when MyModule::SomeDomain::BETA_USERS,
346
+
MyModule::SomeDomain::INTERNAL_RELEASE
347
+
stack.pop + stack.pop
348
+
when :int_literal,
349
+
:some_complicate_explicit_name,
350
+
:graduate_borrowers_with_arms,
351
+
:str_interpolated
352
+
token.value
353
+
end
354
+
```
355
+
356
+
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:
357
+
358
+
```Ruby
359
+
# bad
360
+
361
+
case token
362
+
when :star_op
363
+
stack.pop * stack.pop
364
+
when :slash_op
365
+
stack.pop / stack.pop
366
+
when :minus_op, :minus_minus_op
367
+
also_calculate_that
368
+
stack.pop - stack.pop
369
+
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
370
+
stack.pop + stack.pop
371
+
when :int_literal, :some_complicate_explicit_name, :graduate_borrowers_with_arms, :str_interpolated
372
+
token.value
373
+
end
374
+
```
375
+
376
+
The 'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated
377
+
378
+
329
379
* <a name="indent-conditional-assignment"></a>
330
380
When assigning the result of a conditional expression to a variable,
0 commit comments