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 instance开发者_JAVA技巧s of a method or variable, renaming classes sitewide, etc?
You can check out Vim Ruby Refactoring. It has several useful refactoring patterns.
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.
I also love Resharper for C# development-- I know Jetbrains released a Ruby IDE called RubyMine that includes refactoring tools, etc. I've been meaning to try it out but I prefer Textmate on my Mac. Not sure about VIM tools, though.
Jetbrains puts out an IDE RubyMine that does have some basic functionality of refactorings, no where near the power of resharper(surprising as its the same company putting out both prodcuts). I tend to only use rubymine after stumbling upon it a few months back.
精彩评论