Get to Know a Gem: Rak
6 comments Latest by zblmw Mon, 08 Sep 2008 01:10:19 GMT
A few months ago, I posted about an article that showed you how to colorize your grep search results. Since then, I’ve heard people talking about ack, which describes itself as…
“a tool like grep, aimed at programmers with large trees of heterogeneous source code.”
It’s written in Perl, which is fine and dandy… but before I installed it, I heard that there was a Ruby version named rak, which describes itself as…
“a grep replacement in pure Ruby. It accepts Ruby syntax regular expressions and automatically recurses directories, skipping .svn/, .cvs/, pkg/ and more things you don’t care about. “
Sounds great. Let’s see what this thing can do.
Installing rak
Daniel Lucraft, the author of rak, was kind enough to package it up as a Rubygem. So, all we have to do is install it via gem install rak.
> sudo gem install rak
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rak-0.8.0
Installing ri documentation for rak-0.8.0...
Installing RDoc documentation for rak-0.8.0...
~ >
Great, let’s move on.
Using rak
Now that it’s installed, we can use Rak by typing rak from the command line. You’d typically want to run this from within the root of your application.
For example, basic usage would look like the following.
$ rak search-pattern
In my first test, I ran rak README.

Immediately, I see a greater advantage to rak over using grep and that’s because it’s giving me line numbers for free, which takes remembering a few extra options with grep.
Like grep, we can specify a specific path to search with. For example, we use a view helper named link_to_unimplemented to help us track actions that aren’t implemented yet. Looking at a current project, I can run rak link_to_unimplemented app/views and produce the following results.

I’m going to keep playing with it, but wanted to help get the word out. If you have any tips on using it, please share them in the comments. :-)
Enjoying the content? Be sure to subscribe to my RSS feed.






rak is sweet. Only downside is it’s so close to “rake” I’ve accidentally typed that a few times…
Hey Robby, nice find.
I’ve been using Yehuda Katz’s implementation of grep in Textmate. My post about Yehuda’s post has instructions (if you look at the previous posts). (Warning: nested posts ahead. ;)
It’s cool, problem is it’s dreadfully slow when compared to ack (which it seems to have perfectly copied in terms of functionality).
Yeah, it does feel very slow. Using it to search a medium sized rails project completed quite a bit quicker than an equivalent grep, but 3-4 times longer than ack.
Switching to ruby 1.9 took that down to 2.5 times longer, but that’s still long enough that I’m going to stick with ack for now.
Great write-up. Rak is slower than Ack for sure. I’ve been meaning to try it with 1.9, thanks for the info James.
There are some speed improvements that can be made, but I suspect it would be veryhard/impossible to make it faster than the equivalent Perl code.
珠宝联盟网