This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 325d536990584fa2ad7cd9ca85ce33710de5324b
tree a2851ad80bfc94b3c593f0be15ede646d3b220c4
parent 90f85ab2d53bfad3158fe811262b58d715dce8a5
tree a2851ad80bfc94b3c593f0be15ede646d3b220c4
parent 90f85ab2d53bfad3158fe811262b58d715dce8a5
grep /
| name | age | message | |
|---|---|---|---|
| |
README.markdown | ||
| |
grep.gemspec | ||
| |
lib/ | ||
| |
test/ |
README.markdown
grep
Yes, there are already a couple of grep gems around - but they didn't do things the way I wanted, and weren't easy to fork. So here's mine.
Installation
To perform a system wide installation:
gem source -a http://gems.github.com
gem install JasonKing-grep
Just require it, it just reopens Dir and File and adds the grep instance method to each of them. You pass it a regular expression and it returns an array of hashes, very simple:
:match => Contains the MatchData object (so you can add parens and capture parts)
:file => Contains the File#path where the pattern matched (mainly useful for the Dir)
:lineno => Contains the line number where the pattern matched
:line => Contains the full line from the file where the pattern matched
That's it, I think that's the best grep you can have. Call it on a Dir object and it will drill down through the directory, matching as it goes. Call it on a File object and it will just match in that file.
Usage
require 'grep'
f = File.open('foo')
m = f.grep(/^\s*Include\s+(\S+)/)
m.first[:match][1] # => captured parens expression
Contributors
- Jason King (JasonKing)








