Monday, September 7, 2015

Installing and Using Ruby Interactive Shell on Windows

      Ruby is dynamic,interpreted, object oriented programming languages which is one of the easiest programming language to learn and with Rails its just might be the best web development option at the moment. Ruby intsallation is pretty much simple in windows, Linux and you don't have to install Ruby on Mac. It already has Ruby installed in it.

   Step by step guide to install Ruby on your PC:
  1. Go to Ruby programming language homepage:
  2. Click downloads
  3. Click on Installation-->click on RubyInstaller(Windows)-->Ruby installer-->Download
  4. Select the top selection there that will be the current version of Ruby 
  5. Click save file. let it download
  6. Now double click the file-->accept license agreement-->Install-->finish.

Using Ruby Interactive Shell 

        The interactive shell  or just a shell allows us to type Ruby statements or expressions at the command line and gives immediate result. So open the command prompt and navigate to the folder where Ruby is installed and type "irb".

On ruby shell single number evaluates itself. We can perform simple arithmetic operations the ways show above screenshot. Strings also evaluate to them self, We can perform concatenation operation between two strings using '+' operator as shown below :

         We can also store data in variables and use it later as shown in below "greet' is variable which stores value "good morning". After typing good morning it returns "good morning".

   We can also concatenation "greet" with other value 

    We can write more complicated expressions in ruby shell. We can create functions for example square function in bellow example. Here I wrote my own user define "sqr" function to find square of a number.
     If you have good understanding of function you not even have to write return statement. lets consider following function for addition of two numbers. In which I wrote add method for addition of two numbers when next time I write add(2,2)  it performs addition of these two numbers which is 2+2=4.