rubocop / rubocop/ruby-style-guide

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

Open Beginner friendly
#884 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
16.5k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

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.

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

Search the guide for existing recommendations about select, reject, grep, or regular-expression matching, then read the surrounding style guidance. Confirm the Ruby 3 performance rationale from the linked references; done means the equivalent grep and grep_v preferences are documented consistently with the stated examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.