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

PreferredMethods: select is not an equivalent substitute for find_all #1084

Closed
fj opened this issue May 12, 2014 · 4 comments
Closed

PreferredMethods: select is not an equivalent substitute for find_all #1084

fj opened this issue May 12, 2014 · 4 comments

Comments

@fj
Copy link

fj commented May 12, 2014

Rubocop's presumption with PreferredMethods seems to be that the "undesired method" is equivalent to the more idiomatic "desired method", so we should use that one.

However, that's not accurate in the case of select and find_all. Consider, e.g., the following simple case:

h = {:a => 1, :b => 2}
# => {:a=>1, :b=>2}

h.find_all { true }
# => [[:a, 1], [:b, 2]]     # <---\
                            #     |
                            #  (these are different!)
h.select { true }           #     |
# => {:a=>1, :b=>2}         # <---/
@bbatsov
Copy link
Collaborator

bbatsov commented May 12, 2014

@fj Limitation of static analysis... Both methods are actually the same in Enumerable, but some classes like Hash have a custom select and don't make find_all its alias.

@fj
Copy link
Author

fj commented May 12, 2014

OK. Seems like there's no real way to address this short of an implementation change in Ruby itself, so should I go ahead and close this?

@bbatsov
Copy link
Collaborator

bbatsov commented May 13, 2014

I'll think some more what we can do about this. /cc @jonas054 @yujinakayama

@fj
Copy link
Author

fj commented Oct 18, 2014

👍

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

2 participants