rubocop / rubocop/ruby-style-guide
Unspecified Style point: obj.is_a? vs obj.class == Class
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
Although the case equality operator === is mentioned, of the two methods of class checking demonstrated here:
"this string".is_a? String # => true
"this string".is_a? Object # => true
4.is_a? Object # => true
"this string".class == CSV # => false
4.class == Fixnum # => true
4.class == String # => false
Neither are stated as preferred. I think it's fairly well agreed that is_a? is the the more Ruby way of doing things, but I've seen obj.class == Classname fairly often as well and it's easily readable.
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
The issue names no file or test; start by locating the style-guide section containing these class-checking examples and review the existing discussion. Done means the guide explicitly states whether is_a? or obj.class == Classname is preferred, or clearly documents when each is appropriate.
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
- 35/100