Ruby & code-completion [with Vim]

These days I was looking for an environment for ruby, which provides advanced development helper stuff (like code completion for example).  Because of the issue, that ruby is an out-and-out dynamic language, such help provider turn out to become a very complex topic.

However, after all I discovered a quite nice editor-independend tool-collection, called rcodetools. Information is available at RubyForge and here.

rcodetools is a collection of Ruby code manipulation tools for automagic Test::Unit(RSpec) assertion generation, code annotation, 100% accurate code completion, code and documentation browsing, precise method information (rcodetools is meta-programming aware)…

rcodetools 0.7.0 introduces “test-driven completion” (TDC) which allows 100%-accurate completion while alternating between implementation and tests. Several new mechanisms allow faster development in large projects, and xmpfilter supports RSpec’s latest syntax.

rcodetools can be used with any editor, but it ships with emacs and vim support.

Since I’m a Vim-user, it’s perfect to me … and the deployment is rather easy, if you know what to do. ;-)

Assuming Ruby and RubyGems are installed and working, you can simply install it via RubyGems:

gem install rcodetools
gem install fastri

The last one you’ll just need, if you want documentation browsing support. Though I thought, RubyGems does it automatically,  I additionally had to execute the particular setup.rb (e.g. /usr/lib/ruby/gems/1.8/gems/rcodetools-0.8.5.0/setup.rb [path may vary]) as root to set it up properly.

As next step, you have to copy the rcodetools.vim from the mentioned gem-directory into the Vim‘s plugin-directory: in my case: ~/.vim/plugin/).

If you want documentation browsing support, you’ll have to add following line to your Vim-config (~/.vimrc):

let g:rct_completion_use_fri = 1

. Again, this will only work, if you install fastri first. Every time you wanna use it, fastri-server (shipped with the gem) must run.

Now everything should be set up proberly and working. Here is a nice screen-view, how it should look like:

Vim with Ruby code-completion.

At last, one important thing is to say about it: Be aware of the side effects of such technologies! As mentioned above, Ruby is a dynamic language. This means, the plugin has to execute your ruby code to obtain the information it needs. For instance this sideeffect takes place, if your code is deleting a file or sending an email. While you are using the code-completion feature, your code is executed before you really want to. So your file is already deleted or the email is already sent, before you start your program.

Ruby, Qt4-Bindings, and Gentoo

As I wrote in the About-section, I was waiting for a chance to increase my experience with ruby. And I got one! However, the “chance” itself is not of importance in this post

Fact is, the decision had to be made, which GUI-framework I want to use in the future. Since I’m a KDE user and KDE’s used framework is Qt4 and since I nearly heard only good things of it (not to mention, it’s open source now), I choose to use it: Qt4. The next logical step was, of course, to look for bindings for Ruby and install them. Sounds easy, but it barely was.

After a unsuccessfull look into the Gentoo portage-tree, I tried my luck in the web. And here (a RubyForge project) it is. Okay, at least there exists a stable version, but building it myself is the last thing I wanna do. I gave RubyGem a try. It’s the Ruby’s package manager, which is delivered with Ruby. I found the right package in the repository, but it was only a win32-version, so it’s not of use for me. At next, Google told me about a qt4-qtruby-ebuild in the qting-edge portage-overlay. Adding the overlay and emerging the ebuild brought me following:

Scanning dependencies of target smokeqt
[ 32%] [ 34%] Building CXX object smoke/qt/CMakeFiles/smokeqt.dir/smokedata.o
[ 36%] Building CXX object smoke/qt/CMakeFiles/smokeqt.dir/x_1.o
Building CXX object smoke/qt/CMakeFiles/smokeqt.dir/x_2.o
/dev/shm/portage/dev-ruby/qt4-qtruby-2.0.3/work/qt4-qtruby-2.0.3_build/smoke/qt/smokedata.cpp:6086:
error: expected ‘}’ before ‘com’
/dev/shm/portage/dev-ruby/qt4-qtruby-2.0.3/work/qt4-qtruby-2.0.3_build/smoke/qt/smokedata.cpp:6086:
error: expected ‘}’ before ‘com’
/dev/shm/portage/dev-ruby/qt4-qtruby-2.0.3/work/qt4-qtruby-2.0.3_build/smoke/qt/smokedata.cpp:6086:
error: expected ‘,’ or ‘;’ before ‘com’
/dev/shm/portage/dev-ruby/qt4-qtruby-2.0.3/work/qt4-qtruby-2.0.3_build/smoke/qt/smokedata.cpp:6086:
error: expected declaration before ‘}’ token
make[2]: *** [smoke/qt/CMakeFiles/smokeqt.dir/smokedata.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [smoke/qt/CMakeFiles/smokeqt.dir/all] Error 2
make: *** [all] Error 2

Disappointment after disappointment …

After some time searching the web for answers, I finally found a appropriate bugreport. It told me to make use of the kdebindings-ruby-ebuild from the kde-overlay (never saw it before). I emerged it, and violá: after spending a day searching the one word kdebindings-ruby, the bindings were finally installed.

I even managed to get my first Hello World-program running:

require 'Qt'

app = Qt::Application.new ARGV

hello = Qt::PushButton.new "Hello World!"
hello.resize(100,30)
hello.show

app.exec

Hello World!

By the way this is my first blog-entry, so this program seems to be quite suitable. ;-)

Follow

Get every new post delivered to your Inbox.