ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

Add guidance for safe navigation operator (`&.`)

Open andyw8 opened this issue 4 years ago • 1 comments

Reading https://thoughtbot.com/blog/ruby-safe-navigation reminded me that over-use of &. is common. I think it would be helpful to add a guideline such as:

Avoid long chains of &.. Replace with . if they introduce unnecessary conditional logic. Consider other approaches such as delegation.

This could also be added as a rule in RuboCop with a maximum number of chained calls (e.g. 2 or 3).

andyw8 avatar Oct 14 '21 15:10 andyw8

Yeah, I agree. We should definitely add some guidelines about &..

bbatsov avatar Dec 26 '21 17:12 bbatsov

Created PR for it please review it https://github.com/rubocop/ruby-style-guide/pull/912

Gauravpurohit409 avatar Dec 25 '22 10:12 Gauravpurohit409

Fixed in #912

pirj avatar Nov 17 '23 09:11 pirj