-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Detect opportunities for ||= (double pipe equals) #3965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Makes perfect sense to me. 😀 |
Other possible formats that should be checked for would be x = x || some_value
x = some_value unless x
x = some_value unless defined?(x) |
Think it's worth adding: x = some_value if x.nil? |
If we add support for |
RuboCop doesn't detect when code can be written using
||=
. Should it do so?The Ruby Style Guide recommends this coding style: https://github.com/bbatsov/ruby-style-guide#double-pipe-for-uninit
Expected behavior
Given code like
I would expect RuboCop to tell me to use
x ||= 42
rather than the ternary operatorActual behavior
RuboCop doesn't make a complaint.
RuboCop version
The text was updated successfully, but these errors were encountered: