Ruby Snippets in Eclipse / Aptana

It seems like I am the only rails dev who uses windows. I guess it’s because I can get a blazing windows machine for $600 as opposed to the same mac for $3000. The one thing that I see that macs have over the windows environment is textmate, but it’s not worth $2450 for me to get it. I personally use Eclipse Ganymede with the RadRails plugin from aptana (along with subclipse for vc and mylyn for bug tracking integration with trac). The cool thing that textmate has that makes me jealous is the way it does code completion (I believe they are called snippets).

Luckily, Aptana / Eclipse supports the same thing with a couple caveats. In the Eclipse environment, Ctl+Space is used for completion rather than the simple tab see here for details on why. Since there are a metric ton of different templates (snippets), I am going to pick out a couple that I use frequently. <> will denote the Ctrl+Space sequence.

def<> Method definition (highlights method name)
do<> Do Block
ea<> Each with Inline Block
eap<> Each Pair with Inline Block
if<>, else<>, elsif<> You get the idea
ifelse<> If-else block
hp<> Hash pair a la :stuff => “things” (my personal favorite)

This is only a small sample, but just like anything, it will be easier to remember a small subset and add as you find more things that you type often, you can either find an existing template or write your own. You can find a list of templates by going to Window-> Preferences -> Ruby -> Editor -> Templates (may be different for aptana studio). Tabbed text entry points are denoted by ${variable_name} in the templates.

  • http://fabianosoriani.wordpress.com/ Fabiano

    Excelent, just what I needed to know.

    I can confirm, in Aptana RadRails the path (Window-> Preferences -> Ruby -> Editor -> Templates ) is the same!

    BTW, look at: http://docs.aptana.com/docs/index.php/Adding_a_new_Snippet
    How darn complex they made it :s