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

Non Nil in boolean methods #946

Closed
geniou opened this issue Apr 3, 2014 · 6 comments
Closed

Non Nil in boolean methods #946

geniou opened this issue Apr 3, 2014 · 6 comments

Comments

@geniou
Copy link
Contributor

geniou commented Apr 3, 2014

In my opinion a method with a ? at the end should return a boolean value, but if I write code like

def signed_in?
  !current_user.nil?
end

or

def signed_in?
  !!current_user
end

I get a message from rubocop. I know, that

def signed_in?
  current_user
end

should work as well, but I would expect the return of this method to be a boolean - not an user object.

Is there an idea, without disabling this cop?

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 3, 2014

Such distinction seems irrelevant to me. The check can be refined, of course, as this would mostly resolve the only actual problem with it (which we discussed with @yujinakayama yesterday):

def value_set?
  !@some_boolean.nil?
end

@geniou
Copy link
Contributor Author

geniou commented Apr 3, 2014

Sorry - I got a mistake in my first example.. I fixed it.

@fabiopelosin
Copy link
Contributor

I share @geniou views.

@bbatsov bbatsov closed this as completed in 55d35ee Apr 5, 2014
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 5, 2014

Done.

@fabiopelosin
Copy link
Contributor

💙

@geniou
Copy link
Contributor Author

geniou commented Apr 5, 2014

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants