Introducing RubyDiff

You’re probably working too hard. Do any of these sound familiar?

  • An entire file shows up in your diff, you think it’s because someone changed the tabbing from 4 spaces to 2 spaces, but you aren’t sure so now you’re pouring over all the code.
  • Your co-worker decided to rearrange all of the methods in awesome.rb, but you didn’t notice they also changed the parameter order on one of the methods.
  • There are a pile of small changes in large methods, and your diff didn’t show you what the method names were.
  • You have no idea what you have been working on for the last 2 hours, and can’t remember what to put in your check in message.

If they don’t, then humor me and pretend that they do, because I’m trying to motivate this tool I just wrote and I want you to be interested. What you secretly have been wanting is not a textual diff, but a logical diff, and that’s exactly what RubyDiff does (neat!). So grab it now:

sudo gem install ruby_diff

RubyDiff scans over your code and builds a logical model which it can use to tell you the really important high level information you need. Lets take a look at two versions of my enterprise pancake code:

Sample Version 1

module Food
  class Pancake
    def is_yummy?

    def << ingredient
      puts "adding #{ingredient}"

      p =
      ingredients.each{|i| p << i}

Sample Version 2

module Food
  class Pancake
    def << ingredient
      (@ingredients ||= []) << ingredient

    def self.about
      puts "A delicious morning treat"

    def is_yummy?

  class PancakeFactory
    class << self
      def build(ingredients)
        p =
        ingredients.each{|i| p << i}

Now, the important thing here is not that waffles are better, but that a bunch of things have changed, and the question is… what was it?

ruby_diff test_a.rb test_b.rb
c  Food
c    Food::Pancake
c      Food::Pancake#<<
+      Food::Pancake.about
+    Food::PancakeFactory

RubyDiff shows us that the module Food has changed, within it the Pancake class changed. The class method was removed and a new PancakeFactory class was added. We also see that the append operator was modified and there is a new class method about. Great!

Best of all you can run ruby_diff over an entire repository of code, and it even supports git. For instance to see what changes you have made locally you can do something like:

ruby_diff --git HEAD --file ./
(your amazing changes here)

Or just to be meta, compare two revisions of RubyDiff:

ruby_diff --git HEAD~4 --git HEAD~3
c  CodeChange
c    CodeChange#initialize
c    CodeChange#to_s
c  CodeComparison
c    CodeComparison#changed
c  CodeObject
+    CodeObject#child_signatures
c  StructureProcessor
c    StructureProcessor#diff

I’ll post more about RubyDiff shortly, but the source is available now on rubyforge and you can branch it on github.  It’s still in it’s early stages, so I’d love to hear what you think.



Filed under ruby

11 responses to “Introducing RubyDiff

  1. This looks pretty cool.

  2. I’m curious to find out what blog system you have been working with?
    I’m having some small security problems with my latest blog and I’d like to find something more safeguarded.
    Do you have any solutions?

  3. Thanks to my father who stated to me about this website, this blog is genuinely awesome.

  4. Hey! I just wanted to ask if you ever have any trouble
    with hackers? My last blog (wordpress) was hacked and I
    ended up losing a few months of hard work due to no data backup.
    Do you have any solutions to stop hackers?

  5. I’ll right away take hold of your rss as I can not find your e-mail subscription hyperlink or
    newsletter service. Do you’ve any? Please allow me realize so that I
    may just subscribe. Thanks.

  6. If you are an eczema sufferer, try to remove the
    anxiety in your life.

  7. Stay away from positions that provide you funds prior tto employment.

  8. Hey there I am so excited I found your site, I really found you
    by error, while I was searching on Google for something else, Anyways
    I am here now and would just like to say many thanks for a marvelous post and a all round thrilling blog (I also love the theme/design), I don’t have
    time to read it all at the minute but I have saved it and
    also added in your RSS feeds, so when I have time I will
    be back to read a lot more, Please do keep up the awesome job.

  9. Wow, that’s what I was looking for, what a material!
    existing here at this website, thanks admin of this

  10. M88

    Hi there to all, how is everything, I think every one is
    getting more from this web site, and your views are pleasant in support of new visitors.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s