Skip to content
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

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

Open
dennisvandehoef opened this issue Jun 12, 2019 · 1 comment
Labels

Comments

@dennisvandehoef
Copy link

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?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 12, 2019

I completely agree. I'll just add that apart from arrays we have other collections that might be a reasonable result (e.g. hash, set, etc), plus a multi-value return.

@pirj pirj changed the title Sugesstion: method name should make clear how manny results are expected Sugesstion: method name should make clear how many results are expected Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants