Step by step guide to install Ruby on your PC:
- Go to Ruby programming language homepage: https://www.ruby-lang.org/en/
- Click downloads
- Click on Installation-->click on RubyInstaller(Windows)-->Ruby installer-->Download
- Select the top selection there that will be the current version of Ruby
- Click save file. let it download
- 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.