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

[idea?] Using ternary with array push operator

Open nerixim opened this issue 1 year ago • 0 comments

When using ternary with array push operator, the result may surprise you depending on your knowledge of operator precedence.

array = []

# bad
array << true ? 1 : 0
=> 1
# array = [true]

# good (?)
array << (true ? 1 : 0)
# array = [1]

nerixim avatar Aug 26 '24 09:08 nerixim