Read my latest article: Launching Rails projects, an open call for lessons learned (posted Tue, 23 Jun 2009 17:33:00 GMT)

Get to Know a Gem: Rak

Posted by Robby Russell Tue, 11 Dec 2007 17:10:00 GMT

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. :-)

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Justin Tue, 11 Dec 2007 19:03:13 GMT

    rak is sweet. Only downside is it’s so close to “rake” I’ve accidentally typed that a few times…

  2. Avatar
    Steven Bristol Wed, 12 Dec 2007 00:53:48 GMT

    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. ;)

  3. Avatar
    Stephen Waits Wed, 12 Dec 2007 01:41:34 GMT

    It’s cool, problem is it’s dreadfully slow when compared to ack (which it seems to have perfectly copied in terms of functionality).

  4. Avatar
    James Stewart Wed, 12 Dec 2007 13:05:54 GMT

    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.

  5. Avatar
    Daniel Lucraft Tue, 18 Dec 2007 14:52:06 GMT

    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.

  6. Avatar
    zblmw Mon, 08 Sep 2008 01:10:19 GMT

    珠宝联盟网

    中国珠宝联盟网(zblmw.com)是一家服务于中国大陆及全球华人社群的领先在线珠宝媒体及增值资讯服务提供商。中国珠宝网站拥有多家地区性网站,以服务大中华地区与海外华人以及珠宝企业为己任,通过为广大网民和政府企业用户提供网络媒体及娱乐、在线用户付费增值/无线增值服务和电子政务解决方案等在内的一系列服务。
    专业珠宝门户——中国珠宝网站预计2008年在全球范围内注册用户超过500万,日浏览量能最高突破8000万次,将成为中国大陆及全球华人社群中最受推崇的行业互联网品牌。
    高效的整合营销服务——凭借领先的技术和优质的服务,中国珠宝网站会深受广大网民的欢迎并能享有极高的声誉。
    http://www.zblmw.com

Share your thoughts... (really...I want to hear them)

Comments