Skip to content

Commit ad68059

Browse files
author
Zachary Jones
committed
add style for multi-condition when-then blocks
1 parent 7f60efe commit ad68059

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,45 @@ 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
144+
145+
```Ruby
146+
# good
147+
148+
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
162+
```
163+
164+
which reads better than
165+
166+
```Ruby
167+
# bad
168+
169+
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
177+
```
178+
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
180+
181+
143182
* Use empty lines between `def`s and to break up a method into logical
144183
paragraphs.
145184

0 commit comments

Comments
 (0)