Open In App

Ruby Programming Language (Introduction)

Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto (also known as Matz in the Ruby community) in the mid 1990’s in Japan. Everything in Ruby is an object except the blocks but there are replacements too for it i.e procs and lambda. The objective of Ruby’s development was to make it act as a sensible buffer between human programmers and the underlying computing machinery. Ruby has similar syntax to that of many programming languages like C and Java, so it is easy for Java and C programmers to learn. It supports mostly all the platforms like Windows, Mac, Linux.

Ruby is based on many other languages like Perl, Lisp, Smalltalk, Eiffel and Ada. It is an interpreted scripting language which means most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. Ruby programmers also have access to the powerful RubyGems (RubyGems provides a standard format for Ruby programs and libraries).



Beginning with Ruby programming:
1. Finding a Compiler:
Before starting programming in Ruby, a compiler is needed to compile and run our programs. There are many online compilers that can be used to start Ruby without installing a compiler:
https://www.jdoodle.com/execute-ruby-online
https://repl.it/
There are many compilers available freely for compilation of Ruby programs.

2. Programming in Ruby:
To program in Ruby is easy to learn because of its similar syntax to already widely used languages.



Writing program in Ruby:
Programs can be written in Ruby in any of the widely used text editors like Notepad++, gedit etc. After writing the programs save the file with the extension .rb

Let’s see some basic points of programming:
Comments: To add single line comments in Ruby Program, # (hash) is used.
Syntax:

# Comment

To add multi-line comments in Ruby, a block of =begin and =end (reserved key words of Ruby) are used.
Syntax:

=begin
Statement 1
Statement 2
...
Statement n
=end

Example:
A simple program to print “Hello Geeks!! Welcome to GeeksforGeeks”

Output:

Note: In the output screen, it can be seen how a program is made to run on prompt.

Explanation: First line consist of single line comment with “#” as prefix. Second line consist of the message to printed and puts is used to print the message on the screen.

As everything has some advantages and disadvantages, Ruby also has some advantages along with some disadvantages.
Advantages of Ruby:

Disadvantages of Ruby:

Applications:

Article Tags :