Introduction to Ruby
Ruby is an object-oriented programming language developed by Yukihiro Matsumoto. Ruby is a dynamic programming language with a complex but at the same time expressive grammar. Ruby also has a core class library with a rich and powerful API.
Ruby is inspired by other low level and object oriented programming languages like Lisp, Smalltalk, and Perl and uses syntax that is easy for C and Java programmers to learn.
Ruby, a dynamic and open source programming language with a focus on simplicity and productivity, has an elegant syntax that is natural to read and easy to write.
Although it's easy to program in Ruby, it is not a simple language.
Features of Ruby
- Object Oriented : Every values in Ruby is an object, even the most primitive things like strings, numbers and even true and false. So, Ruby is a pure Object Oriented Language. Every object has a class and every class has one superclass.
- Dynamic : Ruby is a very dynamic programming language. Ruby programs aren't compiled like C or Java programs. All things in a program are built by the code when it is run. A program can also modify its own definitions while running.
- Singleton Classes : Every object in Ruby has two classes: a
regular class and a
singleton class. An object's singleton class is nameless class whose only instances is that object. Singleton classes are created automatically and make Ruby simple and elegant.
- Metaprogramming : Everything in Ruby are objects. You can use them to learn about them or even modify them, while your program is running. This technique is called metaprogramming.
- Flexibility : Methods can be added to existing classes without sub classing, operators can be overloaded, and even the behaviour of the standard library can be redefined at runtime.
- Variables and scopes : Programmer do not need to declare variables or variable scope in ruby. The name of the variable automatically determines its scope.
var is a local variable.
$var is a global variable.
@var is an instance variable.
@@var is a class variable.
- Exceptions for handling errors.
- Garbage Collector.
- OS - independent threading, which allows you to write multi-threaded applications even on operating systems such as DOS.
- You can write extensions to Ruby in C.
Reasons for choosing Ruby:
- Ruby is a server-side scripting language.
- Ruby can be embedded into HTML.
- Ruby has similar syntax to that of many programming languages like C and Java.
- Ruby supports mostly all the platforms like Windows, Mac and Linux.
- Ruby can be easily connected to Oracle, MySQL, DB2.