Rfactor: Ruby Refactoring for your loved editor

4 Feb

I know we all love Ruby, and doesn’t care that much about not having auto completion/IntelliSense available.

I don’t care that much about auto completion, when coding in Ruby, myself. What I really like in Java IDEs is their refactoring support. Eclipse and IntelliJ IDEA are simply awesome in this space for Java. We still have ReSharper for Visual Studio and others, targeting other languages. Ruby has NetBeans, Aptana RadRails, RubyMine and TurboRuby/3rdRail doing a great job in this area.

But, I have this feeling that most of Ruby developers do not use IDEs (including myself). We are using good text editors, such as TextMate, Vim, Emacs and GEdit. They are good enough. Why would I need something else?

I have to admit. I really miss some refactorings while programming in Ruby. Particularly, the lack of “Extract Method” and “Extract Variable” bothers me. They aren’t even complicated, why hasn’t someone already implemented them?

So, I would like to introduce Rfactor. It is a Ruby gem, which aims to provide common and simple refactorings for Ruby code. RubyParser from Ryan Davis is being used to analyze and manipulate the source code AST, in the form of Sexps.

In theory, we should be able to use Rfactor to power any editor, adding refactoring capabilities to it. I’m targeting TextMate, but I would love to see contributions for others. The TextMate Bundle is hosted on github:

Rfactor TextMate Bundle, with installation instructions

This very first release has support only for basic “Extract Method”: inside methods and without trying to guess the method parameters and return.

Stay in touch, there is much more coming!

Tags: , , , , , , , , , , , , , , ,

20 Responses to “Rfactor: Ruby Refactoring for your loved editor”

  1. Alistair Holt February 4, 2009 at 2:46 pm #

    Interesting.

  2. Luke Redpath February 4, 2009 at 3:16 pm #

    Not possible to tell from the video, so does it handle the passing of variables into extracted methods properly?

  3. Rafael Schouery February 4, 2009 at 3:26 pm #

    Really nice! I’m going to try it right away!

  4. Fabio Kung February 4, 2009 at 3:27 pm #

    @Luke

    Unfortunately not yet, but it is in the plan.

    For now, it isn’t trying to guess anything (parameters and method return).

    If you have some time, take a look at the github repository. Who knows, if you end up wanting to contribute some code? ;-)

  5. Matt Wynne February 5, 2009 at 6:20 am #

    Great stuff. I have been looking for this ever since I first started using Ruby. Thank you.

  6. Ben Vandgrift February 5, 2009 at 12:49 pm #

    Solid!

    Having just started working for HP, I long for the familiar comfort of my Macbook with TextMate to help me out. The bundle is something I’ll definitely give a go.

  7. Luke Redpath February 5, 2009 at 8:48 pm #

    @Fabio,

    I’ll try and take a look if I get some time!

    Luke

  8. Faisal N Jawdat February 6, 2009 at 3:15 am #

    So then I wonder what it would take to extend that to other IDE-style features like code analysis, etc…

  9. David Mathers February 7, 2009 at 4:54 am #

    There’s a python library called rope that does this for python. Maybe you can steal ideas from it:

    http://rope.sourceforge.net/

  10. Fabs February 10, 2009 at 9:33 pm #

    fabiokung-rfactor requires newgem (>= 1.1.0, runtime)

    é uma dependência que não está no tutorial da página do github.

    Terminei de instalar agora ^.^

  11. Fabs February 10, 2009 at 9:38 pm #

    Ups. First, it should be in english. So just simple translate.


    fabiokung-rfactor requires newgem (>= 1.1.0, runtime)

    its a dependency that is not at the github tutorial page.

    Just Finished installing now

    In fact, it’s missing on the tmbundle page (http://github.com/fabiokung/rfactor-tmbundle/tree/master)

    In the section that starts with “If needed, here are the dependencies, individually”.

    Sorry :-) .

  12. Chris February 11, 2009 at 2:40 pm #

    It’d be really cool if it could also extract:

    - view code into helpers
    - controller code into models or protected methods

    (These are Rails-specific, obviously)

  13. Ben February 13, 2009 at 7:20 am #

    I’m checking out the source now and can’t wait to start using it!!

    I really want rename refactoring…

  14. rogerdpack March 3, 2009 at 5:54 pm #

    looks good. I suppose there are a couple of pure ruby text editors:

    shoes simple editor:

    http://github.com/why/shoes/blob/71bb825efd28d3a0514c99f52e9261f17503420a/samples/simple-editor.rb

    arcadia:
    http://arcadia.rubyforge.org/

    maybe they could use it as a plugin, too :P

  15. Christoph March 4, 2009 at 7:06 pm #

    wow!
    we really need this in vim :)

Trackbacks/Pingbacks

  1. Double Shot #385 « A Fresh Cup - February 5, 2009

    [...] Rfactor: Ruby Refactoring for your loved editor – Early work on a refactoring bundle for TextMate. [...]

  2. Rails Thoughts » Blog Archiv » Rfactor: Refactoring for Textmate - February 6, 2009

    [...] Full Story> Rfactor: Ruby Refactoring for your loved editor [...]

  3. Refatorando Ruby no seu editor | VidaGeek.net - February 9, 2009

    [...] o Fabio Kung (um dos gurus brasileiros de Ruby) publicou em seu blog um post sobre a nova ferramenta que está desenvolvendo: o [...]

  4. On Bits » Blog Archive » Notícias do Front #3 - March 27, 2009

    [...] o refatoramento de Ruby. Se você é desenvolvedor, tem um Mac e gosta de Textmate, acho que o Rfactor é uma boa pedida. Eu mesmo ainda não usei muito, mas é uma ferramenta muito [...]

  5. Quora - August 30, 2011

    Is there a way to do Eclipse like Refactoring/Renaming in Textmate?…

    I don’t believe there is any way to do refactoring natively in TextMate, but Find and Replace in Project does the job for me, despite it sometimes being imperfect. You can quickly access it with ⌘⇧F. If you don’t mind installing a third-party plugin,…

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.