File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -325,32 +325,33 @@ foo&.bar
325325
326326=== Safe navigation
327327
328- Avoid chaining of `&.`. Replace with `.` and an explicit check.
328+ Avoid chains of `&.` longer than two . Replace with `.` and an explicit check.
329329E.g. if users are guaranteed to have an address and addresses are guaranteed to have a zip code:
330330
331331[source,ruby]
332332----
333333# bad
334- user&.address&.zip
334+ user&.address&.zip&.upcase
335335
336336# good
337- user && user.address.zip
337+ user && user.address.zip.upcase
338338----
339339
340340If such a change introduces excessive conditional logic, consider other approaches, such as delegation:
341341[source,ruby]
342342----
343343# bad
344- user && user.address && user.address.zip
344+ user && user.address && user.address.zip && user.address.zip.upcase
345345
346346# good
347347class User
348348 def zip
349349 address&.zip
350350 end
351351end
352- user&.zip
352+ user&.zip&.upcase
353353----
354+
354355=== Spaces and Braces [[spaces-braces]]
355356
356357No spaces after `(`, `[` or before `]`, `)`.
You can’t perform that action at this time.
0 commit comments