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

Prefer grep and grep_v to select/reject that does a regexp match (Ruby 3+) #884

Open
dvandersluis opened this issue Sep 15, 2021 · 0 comments

Comments

@dvandersluis
Copy link
Member

Reference: rubocop/rubocop#8327 and rubocop/rubocop#10082

The follow pairs have equivalent behaviour:

array.select { |x| x.match?(REGEXP) }
array.grep(REGEXP)

array.reject { |x| x.match?(REGEXP) }
array.grep_v(REGEXP)

Previous to ruby 3, grep/grep_v had worse performance, but this was fixed by https://bugs.ruby-lang.org/issues/17030, so as of ruby 3, grep could be prefered as it is simpler.

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

1 participant