Introduction

Ruby is a dynamic, reflective, object-oriented, general-purpose, open-source programming language. It is a very simple, friendly and easy to use programming language.Its creator, Yukihiro “Matz” Matsumoto has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life.

Who uses Ruby?

Some of the places where Ruby is used are :

Google SketchUp is a 3D modeling application that uses Ruby for its macro scripting API.

Ruby is being used within Lucent on a 3G wireless telephony product.

Twitter (in its early days) - Twitter was originally built with Ruby on Rails in 2006.

Slideshare - Slideshare allows us to upload and share presentations is built with Ruby on Rails.

GitHub code repository is built with Ruby on Rails.

NASA Langley Research Center uses Ruby to conduct simulations.

A research group in Motorola uses Ruby to script a simulator, both to generate scenarios and to post process the data.

At MORPHA project, Ruby was used to implemented the reactive control part for the Siemens service robot.

Shopify - E-commerce shop that allows users to build an online store is built with Ruby on Rails.

How is Ruby simple?

I will write a code to print Hello World on screen in C, Java and Ruby. Decide yourself which is simpler.

Java

Ruby

How to run Ruby

In Windows

3. Open it from the installed apps ( Start Command Prompt with Ruby ).

To run directly on Interactive Ruby shell ( irb )

4. Start Interactive Ruby shell by entering the command irb.

5. Type the code given below and press Enter and then you can see Hello World printed.

puts"Hello World"

To run from a file

4. Use the command mkdir ruby to make a new folder named 'ruby'.

5. Switch to the folder 'ruby' by using the command cd ruby.

6. Type the Ruby code given below in a file with .rb extension and save it in that folder ( name of our file is hello.rb).

puts"Hello World"

7. Enter the command ruby hello.rb i.e., 'ruby filename' and then you can see 'Hello World' printed on the screen

Now you know how to run Ruby codes and you are ready to go for the next chapter.

In Linux

1. Open terminal ( ctrl+alt+T ).

Check whether Ruby is installed on your computer by entering the command ruby -v. If it is installed, then proceed to next steps otherwise download it. This is a nice tutorial to download Ruby in Ubuntu.

To run from a file

2. Open a new file with .rb extension ( name of our file is hello.rb ) in your favourite text editor ( we are using gedit ).

gedit hello.rb

3. Write the Ruby code given below and save it.

puts"Hello World"

4. To run this code, enter ruby hello.rb (it means that you have to enter 'ruby filename').

Now you can see Hello World printed on the screen.

So, now you know how to write and run Ruby codes from a file.

To run on Interactive Ruby Shell (irb)

2. Enter irb in terminal. Then it will activate Interactive Ruby Shell