Now, we will create a simple application/program along the lines of a Hello World program to make sure the environment is set up correctly, while explaining some of the initial features of the IDE as we go.
You should have already started the assimilation process by completing the recipe First contact – installing Ruby and RubyMine (Must know). If not, go back and restart the assimilation process.
When starting to learn a new language, it is customary to say hello, so let's get started:
Open RubyMine and you will be presented with the Welcome to JetBrains RubyMine window:
Select the option Create New Project.
Use the name HelloWorld in the first box and leave the other two options as default. We are going to start with a simple Ruby application, even though RubyMine can create many different types of project such as a Ruby on Rails project and Twitter Bootstrap Web project.
Your next task is to create a new Ruby file that we can use to begin building our first program.
Navigate to File | New … and you will be presented with a list of various choices of files to create.
Choose the File item, which is simply a Ruby file.
Name it
helloworld.rb
. Don't forget the.rb
extension, as this is necessary to distinguish it from a simple text file, which it really is anyway.Now, type in the following program into this new document that you created:
puts "Hello Biological Life Form. We are the Borg." puts "We will add your biological and technological distinctiveness to our own." puts "Resistance is futile."
This is your first Ruby program in RubyMine! Let's run it using the following steps and see what happens:
Navigate to Run | Run and you will see a window similar to this:
Select the helloworld configuration and it will execute your first Ruby script. The output of your program should then be shown in a window panel below your
helloworld.rb
file. Eachputs
command prints out the string to the console and appends a carriage return to the end automatically. RubyMine captures this output in the window at the bottom of the program.
You have successfully begun your assimilation into the collective—there is no stopping you now.
RubyMine keeps everything inside its various panels so that you don't have to keep switching between your editor, a terminal/console window, and your browser. It lets you see the output of your programs in the Run panel at the bottom of the window, so you can compare the output with what you expected your code to do.
When the main project window opens, you will see a Tip of the Day window, similar to the following screenshot:
I highly recommend that you maintain this tip window while you are processed through the assimilation stage, as it is much easier to learn a few things a day rather than everything all at once. Your internal Borg buffers will overflow otherwise.
With the Borg it is all about efficiency so that assimilation can happen that much quicker.
Each time you create a new project or run a specific file, a new configuration is created so that it is easier to switch between running tests, Rails development, or simply a Ruby program file. Once a configuration is created, it is available in a pull-down menu at the top, as shown in the following screenshot:
When you select a particular configuration, you can then just hit the green arrow button to run or the green button with a bug on it to debug the files in that configuration.
If you want to run a different configuration, just select it from the menu and hit the green arrow. This makes it more efficient to switch between different files or environments.
If you get any errors while running, first check to see that you entered exactly what is in the preceding program. If you still have errors, it might be your Ruby installation and what RubyMine thinks is your Ruby installation. To check that, select the Settings menu item (Mac OS X it is the preferences item in the RubyMine menu, on Windows and Linux it is the Settings command from the File menu).
This is the main window for setting all of the hundreds of attributes of your RubyMine software.
Select the item Ruby SDK and Gems from the left side of this window. You will then be able to select which version of Ruby that you want RubyMine to utilize for your programs.
Once you have selected a version of Ruby, you must then hit the Apply button at the bottom of this window on the right. You can also install a new version of Ruby here and install and manage the Gems needed for your various projects. A Gem is a standard way of distributing libraries of Ruby code for sharing among developers and projects.
While you are at the Settings window, go ahead and explore around and select the various items on the left to see what options are available to you. You are provided with a large number of ways to customize and change how your new assimilated tool will work for you and the common good of the collective.