Ruby is a purely object-oriented programming language originally developed for scripting. It combines syntax inspired by Ada and Perl with Smalltalk-like object oriented features, and also shares some features with Python, Lisp and CLU.
Ruby has many useful features. Ruby also supports Operator overloading and Exception handling. Currently, Ruby lacks Unicode support. Ruby has Iterators (which resemble those in CLU and Sather). Ruby supports Closuress (also found in Smalltalk and many functional programming languages). Ruby has native, syntactic support for Perl-like regular expressions at the language level (not merely in libraries, as in Python or many other languages). Ruby supports automatic garbage collection and Dynamic library loading/linking (depending on the architecture) on Microsoft Windows. Ruby has been ported to many platforms, including Unix, Microsoft Windows, DOS, Mac OS X, OS/2, Amiga, and many more.
Ruby is purely object-oriented: every bit of data is an object, including types that are designated "primitive" in impure languages. Every function is a method. This is similar to Smalltalk but unlike Java and Python. Every named value (variable name) in a Ruby program designates a reference to an object, not the object itself. Ruby supports Inheritances with dynamic dispatch, Mixins, and Singleton methods. Ruby does not support multiple inheritance, but classes can import modules. Although Ruby can have procedural syntax, everything in Ruby is an object, in the sense of Smalltalk, not Perl or Python.
The language was created by Yukihiro Matsumoto (a.k.a. "Matz") on February 24, 1993. The current stable version is 1.8.0. Note that the name is not an acronym--it is actually a pun on Perl. According to the author, he designed Ruby to follow the principle of least surprise (POLS), meaning that the language should be free from the traps and inconsistencies that plague other languages.
From the Ruby FAQ: If you like Perl, you will like Ruby and be right at home with its syntax. If you like Smalltalk, you will like Ruby and be right at home with its semantics. If you like Python, you may or may not be put off by the huge difference in design philosophy between Python and Ruby/Perl.
>> "Ruby is cool".length # length is a method of String objects
>> [11, 5, 7, 2, 13, 3].sort.reverse
=> [13, 11, 7, 5, 3, 2]
# append "!" to variable 'string1'
string1 += "!"
# print variable 'string1', followed by a newline
Here are some examples of Ruby code:
>> -199.abs # The number -199 is an object; the method abs is called.
?> [11, 5, 7, 2, 13, 3].sort
=> [2, 3, 5, 7, 11, 13]
# Execute the following block of code 10 times
# Replace ' ' with ', ' and store in string1
string1 = "Hello world".gsub(" ", ",")More Ruby code is available in the form of sample algorithm implementations in the articles:
>> "Ruby is cool".length # length is a method of String objects => 13
>> "Rick".index("c") => 2
>> "John".swapcase => "jOHN"
>> [11, 5, 7, 2, 13, 3].sort.reverse => [13, 11, 7, 5, 3, 2]
# append "!" to variable 'string1' string1 += "!"
# print variable 'string1', followed by a newline puts string1 }