rubocop / rubocop/ruby-style-guide
Additional thoughts on `self`
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
The style guide currently takes a hard-line position on self that it shouldn't be used unless you're doing an attribute assignment. I would argue that this is actually an over-simplification.
Consider:
selfneeds to be used with operators (e.g.self + other,self - [:x, :y], depends on the domain). In fact, RuboCop even calls this out explicitly as a case whereselfis not penalized because it's required.- clarity in "spaceship operator" comparisons (i.e. sorting methods).
For example:
class Student
def <=>(other)
self.name <=> other.name
end
end
In this case, self helps draw a distinction between a value in the current instance and the other instance. It balances out the comparison.
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
Start by reading the style guide's current guidance on self and the linked RuboCop explanation of required uses. Review the supplied operator and spaceship-comparison examples, then determine with maintainers whether the rule should be revised and what wording and examples would define the completed documentation change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100