My self-inflicted crash course into Ruby – Lesson 1 – Installing Ruby on Windows

I am always curious in learning new programming languages and have been curious for awhile now with Ruby. I have come across various scripts and applications built upon it but have never had the professional need to utilize it. Time I guess to bite the bullet and see what if anything is special about this language built on the old but probably ever living C language.

Installing Ruby

The first thing to do, with any language is installation. What to do I guess first off since I use a Windows machine is to see if thee are any executable Ruby installers. Bingo, hello RubyInstaller a self contained ruby language installer with an inclusive execution environment built in.

Creating my first Ruby script

The common file extension to a ruby script file is .rb. So starting things out I created a test script to echo the basic “Hello World” script to verify Ruby was installed correctly.

puts "hello World!"

A couple things right off the back Ruby does not use semi-colons (;) to terminate a code statement, instead it uses the carriage return. Secondly the command to output to the console is puts… A strange word to use for outputting to the system it is simpler then the Java equivalent of System.out to be sure but the PHP use of echo seems more intuitive then puts.

Being familiar with the command prompt I decided to fire it up and run my script using the new installed ruby library. Having selected to add the library to my environments path from the installer there is no need to specify the path to the Ruby library.

ruby test.rb

I was pleasently delighted to have my script output correctly.

C:test>ruby test.rb
Hello World!

Splitting a ruby command onto multiple lines

Now knowing that Ruby utilizes the new line character to specify the end of a command, I was curious as to how to wraps my ruby commands onto multiple lines. As an avid developer I try to follow common guidelines when writing code one of which is keeping each line of code to within 80 characters improving readability. A quick search revealed that the front slash () character can be used to “join” two code lines together.
For example:

test = 10 + 16 + 
9 + 3

will output:


Lots more to learn and explore next I’m going to tackle Classes and Methods in Ruby with the hope of gathering some insight into why some developers prefer Ruby as their language of choice.

// Ruby //

Comments & Questions

Add Your Comment