Skip to content

Commit c68632c

Browse files
author
Zachary Jones
committed
more clear rendition of in-the-wild when conditions
1 parent ad68059 commit c68632c

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

README.md

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,43 +140,52 @@ You can generate a PDF or an HTML copy of this guide using
140140
end
141141
```
142142

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
144145

145146
```Ruby
146147
# good
147148
148149
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
162166
```
163167

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. It reads better than:
165169

166170
```Ruby
167171
# bad
168172
169173
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
177186
```
178187

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
180189

181190

182191
* Use empty lines between `def`s and to break up a method into logical

0 commit comments

Comments
 (0)