rubocop / rubocop/ruby-style-guide
Constants vs. class methods
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
Greetings,
I would like to hear some community standpoint regarding this matter.
class User < ActiveRecord::Base
ROLES = %w(admin moderator contributor)
end
# > User::ROLES
# => ["admin", "moderator", "contributor"]
or...
class User < ActiveRecord::Base
self.roles
@roles ||= %w(admin moderator contributor)
end
end
# > User.roles
# => ["admin", "moderator", "contributor"]
I personally prefer class methods since this approach looks more object-oriented to me while screaming snake cased constant feels kinda ugly typographically.
There is also interesting Stack Overflow discussion.
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 comparing the two Ruby examples in the issue and reading the linked Stack Overflow discussion. The task is to establish a project style-guide position on constants versus class methods; it is done when the community reaches a decision and the guidance is recorded in the style guide.
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
- Needs clarification
- Newbie friendliness
- 20/100