Ruby is a programming language written by Yukihiro Matsumoto ("Matz"). It combines the cool features of Java, Scheme, Perl and Smalltalk into a coherent language which is very pleasant to use. Ruby is somewhat similar to Python, although personally I find Ruby is nicer. Ruby programmers are known as Rubyists.

There is an online book available at http://rubycentral.com/book/

Main features of Ruby:

  • Much of perl's built in data structures and syntax. You can use Regexps, hash tables and arrays.
    
    # arrays
    
    myarray = [1, 2, 3, 4]
    
    puts myarray[0]
    
    # hash tables
    
    english = {
            "one" => 1,
            "two" => 2,
            "three" => 3,
            "four" => 4,
    }
    
    puts english['one']
    
    # regexps
    
    if "shoenix" =~ /ni/ then
            puts "ni!"
    end
    
  • Object oriented with all the standard OOP features. OOP isnt a pain in the rear like it is with perl. Absolutely Everything is an object in Ruby - there are no base types. You can call methods on numbers, for example.
    # defining a new class
    
    class Shonky
       def monkey
          puts "monkey monkey monkey!"
       end
    end
    
    shoe = Shonky.new
    shoe.monkey()
    
    # absolute value
    
    test = -4
    puts test.abs()
    
    
  • Features from scheme like lambda and call/cc. When calling methods you can attach an associated code block so stuff like iterators can be done really expressively.
    
    mylist = [1, 2, 3, 4]
    
    # print each value in the list
    
    mylist.each { |i|
       puts i
    }
    
    # create a new anonymous function
    
    myfunc = lambda { |num| num+1 }
    
    puts myfunc.call(10)      # 11
    
    
  • The C API for writing extensions is really nice.
  • Comes complete with standard libraries for doing things like remoting (distributed Ruby) and web (HTTP).
  • Proper Mark and Sweep garbage collection.
  • Open Source!

The Ruby way

In using Ruby, you get a feel for "the Ruby way". There is a clear philosophy behind the language, though it is maybe not as loudly expressed as it is in the communities which surround other languages like Perl. The influence of Perl and Scheme is particularly evident in Ruby. Ruby encourages much looser programming than other languages - such as Duck Typing and not having to predeclare variables. Rubyists do not care about execution speed - rather, it optimises towards the programmer.

The future

At the time of writing Ruby has reached version 1.8. Work is soon to begin on Ruby 2.0 - this will be a major revision to the language. The new version will be based on a bytecode interpreter called Rite (cf. Parrot for Perl and Python). This will allow faster execution as well as native threading support.

You can find out more in Matz' Rubycon presentation here:

http://www.rubyist.net/~matz/slides/rc2003/