rubocop / rubocop/ruby-style-guide

assignment in conditional ternary

Open
#704 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

New Rule
Dominant language
No language data
Stars
16.5k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

Should assignment in conditional ternary be avoided ?

something like this

condition ? self.foo = bar : self.foo2 = bar2

it's dealing with operator precedence and it is less clear than

if condition
  self.foo = bar 
else
  self.foo2 = bar2
end

that we are modifying some state

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the style guide's current guidance on ternary expressions and assignments, then compare it with the two Ruby examples in this issue. Determine whether the guide should address assignments in conditional ternaries and make the resulting recommendation explicit, with examples that clearly resolve the construct.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.