rubocop / rubocop/ruby-style-guide

Sugesstion: method name should make clear how many results are expected

Open
#753 1 comment 2 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

Personally, I think it should be possible to know if a method is expected to return == 1 or >= 1 results. I was the opinion that it is part of the style guide already, but I could not find it today.

Of course, a method ending with an s can still return only one result, but it should be an array.

# bad
def rating
  [1, 6, 3, 10, 5]
end

def ratings
  10
end

# good
def ratings
  [1, 6, 3, 10, 5]
end

def rating
  10
end

def ratings
  [10]
end

What are your opinions on this?

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 existing Ruby style guide and the issue's proposed singular/plural naming examples to determine whether a rule is missing. The work is done when the project reaches a decision and the agreed guidance is documented consistently 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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.