The Ruby programming language reference article from the English Wikipedia on 24-Apr-2004
(provided by Fixed Reference: snapshots of Wikipedia from wikipedia.org)

Ruby programming language

For thoughtful child sponsors
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 currently has only one implementation, the Ruby interpreter, although a Ruby front end (called "Cardinal") for the Parrot virtual machine is in planning. It 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 other languages, for example integers. Every function is a method. Named values (variables) designate references to objects, not the objects themselves. Ruby supports inheritances with dynamic dispatch, mixins, and singleton methods (belonging to an instance rather than a class). Though Ruby does not support multiple inheritance, classes can import modules as mixins. While procedural syntax is possible, everything is an object, in the sense of Smalltalk, not Perl or Python. Anything done in Ruby procedurally (ie. outside of the scope of a particular object) is actually done to the Object class. Since this class is parent to every other class, the changes become visible to all classes and objects.

The language was created by Yukihiro "Matz" Matsumoto, who started working on Ruby on February 24, 1993 and released it to the public in 1995. The current stable version is 1.8.1 (as of February 2004). 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 distributed disjointly under the free and open source licences GPL and Ruby License [1].

Table of contents
1 Features
2 Examples
3 External links

Features

Ruby currently lacks support for Unicode, though it has partial support of UTF-8.


Examples

Here are some examples of Ruby code:


>> -199.abs   # The number -199 is an object; the method abs is called.
=> 199

>> "Ruby is cool".length  # length is  a method of String objects
=> 13

>> "Rick".index("c")    
=> 2

>> "John".swapcase
=> "jOHN"

>> #Arrays
>> [11, 5, 7, 2, 13, 3].sort
=> [2, 3, 5, 7, 11, 13]

>> [11, 5, 7, 2, 13, 3].sort.reverse
=> [13, 11, 7, 5, 3, 2]

>> #Iterators (the code block {...} is passed to "collect")
>> "Ruby is cool!".split.collect { |x| x.length }
=> [4, 2, 5]

 # Execute the following block of code 10 times
 10.times {
     # Replace ' ' with ', ' and store in  string1
     string1 = "Hello world".gsub(" ", ",")

     # concatenate "!" to variable 'string1'
     string1 << "!"

     # print variable 'string1', followed by a newline
     puts string1
 }

More Ruby code is available in the form of sample algorithm implementations in the following articles:

External links


Programming languages
Ada | Algol | APL | BASIC | C | C++ | C# | Cg | COBOL | Common Lisp | ColdFusion | Delphi | Eiffel | Forth | FORTRAN | Haskell | Java | JavaScript | Jython | Lisp | Logo | Mesa | ML | Modula-2 | Oberon | Objective-C | Objective Caml | Pascal | Perl | PHP | PL/I | PostScript | Powerbuilder | Prolog | Python | QBASIC | REXX | Ruby | Scheme | Smalltalk | Tcl/Tk | Visual Basic