rubocop / rubocop/ruby-style-guide
[idea?] Using ternary with array push operator
Open
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
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]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by reviewing the style guide's existing operator-precedence and array examples, then determine how this ternary and array-push interaction should be documented. Done means the relevant guidance and examples clearly explain the surprising result and the intended alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100