|RubyMine The Right Way To Do Ruby|
|Written by Alex Armstrong|
|Monday, 29 April 2013|
If you are still using EMACs or some other text editor to build Ruby applications, you need to consider that there are better ways to work. RubyMine is a full Ruby IDE that makes it easy to create and develop complex projects. If you have never used an IDE to program, you may not know what you are missing.
Many Ruby programmers swear by this or that editor, I'm not going to name names for either programmer or editor. The main reason for this is that Ruby doesn't have a standard development environment. Until recently you could use NetBeans to develop Ruby projects but Ruby support was discontinued in Version 7. Since then I have been looking for a replacement IDE with as good support and as important a future. RubyMine from JetBrains is the obvious choice as it is currently being rapidly developed.
You can get a 30-day free trial from the JetBrain's website. After the 30 days you have to register and this costs 89 euros for a personal license, 26 euros for a student license or 179 euros for a commercial licence. For educational use and open source projects the product is free. You also get one year's worth of updates and a licence to use the version you have for ever. If you want to upgrade after the first year you have to pay a smaller amount. So not free, but if you are serious about Ruby programming not excessive.
What do you get for the money?
The reason that RubyMine makes you more productive is that it lets you see many things that you have to remember or guess at when working at the command line. For example, you can start a project and a project template will configure everything for you. If you want to change the project's structure then you can do this using a Project Structure page to work with the files and configuration.
When you get to typing in Ruby code you'll quickly find you become more productive. Syntax highlighting helps you see that what your code means and that it is correct. This would be enough of an advantage to make it worth using RubyMine, but you also get code completion which offers you a selection of possible completions as you type. It also automatically generates obvious closing keywords. That is, you type def and it supplies end. It has to be admitted that when you first start using an IDE with autocomplete it can seem irritating - for example if you have already typed end on auto-pilot while not looking at the screen so duplicating the one generated by the autocomplete. Give it a few minutes and you soon change to relying on it.
One-step project creation
There are lots and lots of other small features that you can overlook when you first start using RubyMine. For example, when you want to find a the definition of a class - easy put your cursor on the class name in the code, press Ctrl+B and you jump to the declaration. This makes finding out how code works a lot easier. Another example is the way closing brace/brackets are highlighted as you place your cursor on the opening brace or bracket. This makes it very easy to check that they are correct. As you use RubyMine you accumulate more and more ways of working with code
There are also a lot of facilities to help with testing and debugging. A code inspection command will scan through your code and tell you if you have any bad practices lurking. This is the sort of feature that is usually an add-on in other IDEs. To help you improve your code there are a number of automatic refactoring tools. If tests are your preferred approach then you can select RSpec, Cucumber, Shoulda, Test::Unit and Test/Spec frameworks. If you don't want to use them then you can ignore them.
Of course when it comes to finding problems the debugger is the star of the show. Here I hit a snag at first that did make it more difficult than it needed to be. When you first run the debugger is builds a database of gems - unfortunately you need the DevKit installed which is not something all Ruby installations have. There was no immediate help provided and I had to find out how to install the latest version of DebKit.
Although I'm sure that this problem will be fixed or documented in the next version of RubyMine what you have to do is:
1) Download the appropriate version of DevKit from http://rubyinstaller.org/downloads/
2) Unpack the DevKit by running the exe you have just downloaded and store it in a directory like C:/DevKit.
3) Using the command prompt change directory to C:/DevKit and use the command: ruby dk.rb init
4) Edit the file config.yml to make sure that it lists the directory that your Ruby is stored in - for my 64-bit Ruby this didn't work. If it hasn't worked add the line:
after the three dashes - change to whatever directory Ruby is stored in and note the leading dash.
After this it all should work. If it doesn't you need to search the forums to see if things have changed since I wrote this.
It is worth the effort to get the debugger running. How anyone can find an even slightly non-obvious bug without a debugger is a mystery. Using RubyMine it is even easier to set up the debugger to find out how your program is behaving. You can set up conditional breakpoints, examine what is in variables, evaluate expressions, set watches for conditions and examine the frames and call stack. It is easy to use and you can switch between the code editor and debug window as you please.
What to tell you about next?
There are so many features that help with both day-to-day coding and special situations and they are all invaluable. However there is the elephant in the room. I have deliberately ignored Rails until now. It is all too easy to think that every Ruby programmer is a Rails programmer and this is certainly not true. RubyMine is a huge advantage to any Ruby programmer, but when it comes to building more complicated multi-file and multi-technology projects like a Rails website then you really do not want to fly without a parachute. Not using RubyMine on a Rails project or similar is more like trying to fly without an airplane.
RubyMine has a special Rails project view and a model diagram that lets you see things in a way that makes sense in Rails terms. Files are organized as models, controllers and views and so on. This makes it easier to find what you are looking for and to see how things relate. The models dependency diagram shows the relationships even more directly. All of this organization is also put to good use in Rails oriented refactoring tools. You can for example rename a model and the associated controller, views and so on will also be renamed. Just as the project template will generate a basic Rails project you can also use the code generator to add Rails entities. Once you get used to the facilities and remember to use them things become remarkable easy.
There are lots of other smaller features, and some features others might regard as major. Did I mention it does version control using Git and other common packages?
A REST Client Tool - another feature I only just discovered!
If you do decided to give RubyMine a try based on my recommendation I have one final word of advice. Don't judge it based on your first few minutes of using it. Give it time to become your natural way to work. I still find that I am discovering shortcuts and even features that either speed up or make what I am doing more accurate after a month of use. I expect this discovery process to continue for a while longer.
Will you be more productive using an IDE? If you give it time to become your way of working then you certainly will.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Monday, 29 April 2013 )|