ruby-style-guide
ruby-style-guide copied to clipboard
Using the safe navigation operator with other operators?
Recently, I came across this:
do_something if value1 &.!= value2
Which was equal parts very cool and startling.
So I wanted to get community feedback on whether or not it was too obscure to be good style. We can add our findings to the style guide, since there is no guidance on it yet
My feeling is that these should be highly discouraged for use with comparison operators.
do_something if value1 &.!= value2
# not the same as
do_something unless value1 &.== value2
I personally can't grok either of the above and I have to "unroll" those in my head.
For other operators I am neutral:
ary &.<< elem
foo &.+ bar
They all seem somewhat confusing to me, especially the comparison ops. Generally, I find it weird you'd care about a nil check in a comparison anyways.