RUBY Programming Language: A Guide

Ruby is an object-oriented programming based language, it focuses on simple and easy syntax. It has a graceful syntax that is natural to read and easy to write. It is different from other languages like much as Python and Perl. Here in this article, I am going to explain about new creative programming language step by step.

I hope this article will be more helpful and beneficial for the beginners. So let’s start…

Introduction to Ruby Programming Language

It is a pure object-oriented programming language. Yukihiro Matsumoto of Japan in 1993 searched a dynamic programming language. While in the physical world “Ruby ” refers to a red gemstone, but in the computer world, it is a scripting programming language. Here gemstone means such type of gift according to Vedic astrology, Gemstone plays a significant role in our lives. There are a number of gemstones such as Red Coral gemstone etc. There are a number of benefits of the Red Coral gemstone. It impacts on the mental health of the person. A person who is suffering from mental depression can wear this gemstone.

This is an open source programming language like PHP and Python, which means it is free to download and use. It can be compiled and run on the different operating system including Unix, Linux, and Windows.

Furthermore, this considers similar to PERL and Smalltalk programming languages. The Ruby syntax is very basic and it is completely object-oriented. Everything is an object in language. Each and every code have their own properties and actions. Here, properties refer to variables and actions refer to methods.

Ruby is freely available for development and deployment. Its programs are compact, yet readable and maintainable. In many languages, Numbers and primitive types are not object. But in this language, everything calculates as an object.

Why the name “Ruby”?

Python is not a fully object-oriented language. It is a pure object language, Ruby’s father Matsumoto wants a programming language which probably completes the object-oriented language and should be easy to use as a scripting language. Hence he developed one.

The name Ruby originate during a chat session between Matsumoto and KEIJU ISHITSUKA. Two names were selected “CORAL” and “RUBY”. Matsumoto chooses later one “Ruby”.

Scripting language means a language that is no need to compiling before execution or in other words we can say that the language executes directly without compiling.

_____________Object Orientation____________

x=6;

In this x is not a memory of any location where 6  a value store. “x ” is an object of Fixnum class, where “x” refers to an object where value 6 stores.

Versions of Ruby Language

There are many Ruby versions that have been released to date. The first Ruby version “1.8” released on 4th August 2003. The most stable version is “2.4.0”. Now the current Ruby version released “2.4.0” with some newly added features in December 2016.

Since the first public released of Ruby .95 was announced in Japanese Newspaper on December 21, 1995. In  2003 first Ruby book “Programming Ruby” was published. After its publishment learner of Ruby increased throughout the world.

Since 2005, they released their first this programming framework “Ruby on Rails”. The framework release was a huge success.

There are following versions are here-

  • Version 1.8 released in August 2003
  • 1.9 released in December 2007
  • 2.0 released February 2013
  • 2.1 released in December 2013
  • 2.2 released in December 2014
  • 2.3 released in December 2015
  • 2.4 released in December 2016
  • 3.0 future release

The current version 2.4.0 was released on Christmas 2016. This has lots of features like an improvement to hash table, instance variable access, Array# max, and # min.

Features of the Ruby language

There are many features of this programming language like much as Python and Perl. Some of them are given-

  • It is object-oriented and free to use and download from their official website.
  • This is an interpreted programming language that means no need to compiling before executing scripts.
  • This is a server-side scripting language like Python and Perl.
  • It is also helpful for browse based programming.
  • Ruby can be embedded with hypertext markup language(HTML).
  • It has a simple and easy syntax, Any learner can be learned easily and start programming.
  • This is a case-sensitive programming language this means if you write a string like “LOGIN WORKS” and one another string is “login works“, Both are not same so this is a case-sensitive language.
  • It can be used for developing web-based applications and windows based applications.
  • This programming has nice features it can be easily connected to many databases like as DB2, MySQL, Oracle, Sybase etc.
  • This has a number of built-in functions, which can be used directly in the ruby scripts without defining it first.
  • It supports many graphical user interface(GUI) tools.
  • This also provides the facility of data abstraction due to data integration service, therefore, this means ruby generally prefers English keyword and some punctuation to decorate ruby. It does not need to the variable declaration.

Advantages of the Ruby language

There are number of advantages of ruby here some of given-

  • It is a portability facility this means it can be run on different operating systems like Windows and another operating system. Portable means simply we can say that it can execute on different consequently platform/hardware.
  • Flexibility: One more advantage of this language is flexibility. This means you can redefine, remove or add existing parts in the script which you want to.
  • This supports only single inheritance. Furthermore, this programming maintains a number of classes and modules. A class is a combination of objects and modules. In modules only methods define. A module can mix into a class, which adds the method of that module to the class. For example, let’s see
                               class MyArray
                                    include Enumerable
                                end
  • This programming has over 60000 built-in libraries functions due to its less complex functionality. These all functions seems like much as predefined function. Because there is no need to define again in the scripts.  Probably it directly can call and use.
  • It’s Data abstraction: It uses very limited punctuation and usually prefers English keyword. It needs no variable declaration.
  • In the conclusion, this programming has a simple Naming Conventions to denote the scope of the variable.
  1. the log could be a local variable.
  2. @log is an instance variable.
  3. $log is a global variable.
  • Exception handling Function: This has exception handling features, like Java and Python rather than other languages to easily handle complex errors.
  • It also provides Garbage Collection facility. Garbage Collection uses to free the memory in which the objects store.
  • Missing Method is one of the important methods to search lost method in this language.
  • Therefore, this is such type of language that provides the facility that there is no need to declare a variable.

How to install ruby on windows and Linux Ubuntu OS?

It is such type of language that can run on the different operating system, different hardware platforms. It installs differently on the different operating system.

  • For Unix like operating system, use your system’s package manager.
  • If you want to install ruby on windows operating system then use Ruby installer.
  • On operating system X machines, you can use third-party tools (RBENV and RVM).

Installing Ruby on Linux Ubuntu

ruby

Download Ruby Installer

The best things are to be download zip version of Ruby Installer, it is better to just download the binaries in the zip.

If you do not want to do this, there are two options:

  • Ruby  2 .3. x
  • Ruby 2. 4. x
Here, we are going to explain how we can install Ruby on Linux with simple and easy way. Follow these steps and go ahead. This version 2.4.x explain here.
  • Open a terminal window.

On Ubuntu, go to Applications->Accessories->Terminal.

Note:  You can do and see these different ways you can open terminal console windows in Ubuntu. It may also refer to as “shell” or “bash shell” in the menus.

  • Run the command which Ruby.
  • If you see a path such as /user/bin/ruby it means a ruby install moreover If you do not see any response or get an error message it means it not install.
  • To verify that you have a current version of Ruby, run the command prompt ruby -v.
  • Compare the version number returned with the version number. 
  • Install appropriate Ruby Packages.
  • On Ubuntu run the following command-

sudo apt-get installs ruby-full.

  • The next step is that open a text editor which install in your system and save the following as test.rb.#!/usr/bin/ env ruby.
  • Put “Hello world!”.
  • In the terminal windows, change directory to the directory you saved test.rb.
  • Run the command chmod +x test.rb.
  • Then run the command ./test.rb.

Installing Ruby on Windows

To install ruby on different windows operating system follow the following steps-

(1).Identify windows version

  1. The first step is to know windows version(x64 or x86).
  2. Press “windows” + “R” button from the keyboard.
  3. Type “dxdiag” and press “OK“.
  4. Identify the system type from the list.

(2).Download zip from Ruby installer(which you may install 7zip):

(3).Save the zip to your hard drive

(4).Unzip to permanent folder

(5). Add to the path:

You can set a path to different windows operating system with the different way:

Windows 7 path

  • Click on start.
  • Right click on “computer” select properties.
  • From the system dialog, select the “Advanced system setting“.

  • Select “Advanced” tab fro the “Environment variable“:
  • From here select the “PATH” variable from the “system variable” panel and select “Edit“:

programming

When the “path” variable setting loads, paste the path to the /bin directory of Ruby, After this click “OK” to exit from it. Now you can set Path to other windows operating system like Windows 10, Windows 8 etc.

Ruby variables

In a computer, programming variable is the value that can change. A variable is a memory location where we can store data. A variable name can be different. These variable names are based on some naming conventions.

Like another programming languages, no need to declare a variable in this language.

Types of variable in Ruby

There are four types of variable in Ruby:

  • Local Variables
  • Class  Variables
  • Instance Variables
  • Global Variables

Local variable: Local variables are the variables that use the block. Also, it is accessible only in the block while the scope of the variable till the block scope. It can start with lower case or (_)underscore.

Class variables: A class variable name starts with @@ sign. If you want to use, first initialize the variable. A class level variable is a variable that uses whole the program. If we change at one place, it’s change apply to the whole program.

Global variable: A Global variable starts with a $ sign. Its scope is Globally it means accessible inside whole the program.

Concluding…

Here in this article, I have tried to define or explain valuable and simple contents. In this blog, I acknowledged about how a learner can learn a new object-oriented programming language “Ruby” easily and start programming. This blog is more beneficial for any beginner which want to do programming in Ruby language.

In this article I have tried to define about object-oriented language, what is Ruby, what is the different advantage of ruby, Explain about how we can install ruby on windows operating system and Linux (Ubuntu) operating system with simple steps.

I hope this article is more beneficial and important for new learners of the “Ruby Programming Language”.

Leave a Comment