1. What is Ruby?

1.1. Some features

Documentation/Library

I think the most important part of a language is it's library. A syntax of a language can be learned quickly in some hours, the library not, and it's the library you are working with the most time.

What I mostly disliked at Perl and Python was, that it is much harder to find a method/function you are searching for. Both have build-in types and use build-in functions. It is very hard to find them in the documentation. For example I spend half an hour (as a guy having written Pyhton programs three year ago) to find a list of methods a Python list-type provides, but I didn't found that neither in the Library Reference nor in the Global Module Index.

Another point is that looking at the Global Module Index shows you around 250 different modules coming with Python (are they really included?). Ruby instead comes perhaps with only 30 modules/classes.

There should always be a differentiaion between the standard library as general purpose library (this should also be platform independent) used in most programs and the libraries for special purposes (e.g. graphics, images, sound...).

Clean object model

Syntax

Lightweight Threads

Build-in Bignums

Iterators and Code blocks

Some usages of iterators:

 a = [1,2,3,4]
 a.each {|i| p i}         # simple iterator
 a.collect {|i| i*i}      # => [1,4,9,16]
 a.select {|i| i > 2}     # => [3,4]
 a.inject(0) {|i, j| i+j} # => sum of all elements

 File.readlines("/etc/hosts").grep( /^A/ ).to_s

You get the methods like collect, select etc. for free; just define method each in your object and mixin module Enumerable.

 File.open( "/etc/hosts" ) do | file |
   ....
 end

 DBI.connect(...) do | dbh |
   sql = "SELECT * FROM X WHERE a = ? and b = ?"
   dbh.prepare( sql ) do | sth |
     sth.execute( ... )
     sth.select {|row| p row["a"] == "test" }
   end
 end

The file or database (or prepared statement) is automatically closed at the end of the block.

Garbage Collector

Powerful and easy to use C interface