Yes, we're talking about Ruby, not the command-line utility!
The .grep
method is the equivalent of the command-line utility. It allows you to filter an Enumerable
using a pattern. There’s even the equivalent of the -v
option to invert the match!
The pattern does not have to be a regex. The method used is ===
which, for example, allows the use of proc.
⚠️ The proc must be passed as a parameter. A block can still be used and will do the equivalent of a .map
.
Link to Ruby documentation for grep
.