Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby refactoring in Vim

I'm a big fan of Resharper in Visual Studio. It has some awesome refactoring tools, similar to what you get in Eclipse for Java. Is there anything like this for Ruby? Better yet, is there a plugin or something into Vim that does refactoring for Ruby code like renaming all instances of a method or variable, renaming classes sitewide, etc?

like image 355
fregas Avatar asked Jun 17 '10 16:06

fregas


2 Answers

You can check out Vim Ruby Refactoring. It has several useful refactoring patterns.

like image 144
sparrovv Avatar answered Sep 19 '22 10:09

sparrovv


The problem with some refactorings in Ruby and other dynamic typed languages, is the lack of information of the type being refactored.

From Cedric Beust blog entry:

A few months ago, I offered the following code snippet to the author of the Ruby Refactoring Browser:

def f1(o)
    o.init
end

def f2(o)
    o.init
end

class C
   def init
      ...
   end
end

And I asked him: "If I rename C.init to C.init2, how do you know which o.init must be renamed in f1 and f2?".

His response was unequivocal:

"This problem is difficult for dynamically typed language. I think computer can't determine whether those must be renamed or not."

"Therefore Ruby Refactoring Browser provides two functions, one is renaming all methods that have same name, and another is renaming only methods and calls that cleary belong the class. The former renames o.init in f1 and f2, and the latter doesn't rename them."

Read the whole entry here: Dynamic language, refactoring IDE. Pick one.

Having said that, Jetbrains has the Ruby Mine IDE which has a good number of refactorings. I'm not sure how they manage this scenario though.

Ruby Mine refactorings http://img709.imageshack.us/img709/917/refactoringsonrubymine.png

There is nothing similar for VIM that I'm aware.

like image 23
OscarRyz Avatar answered Sep 23 '22 10:09

OscarRyz