Ruby's a gem
As with many nice book authors these days (eg. Matt Reilly, Dave Rolskey & Ken Williams), a version (first edition) of the Programming Ruby book is available for free online. There is a second addition for purchasing which apparently covers features and libraries of Ruby version 1.8.
From my reading so far, it will be a snap to pick up for an experienced Perl OO hack like myself. Of course similarity can often lead to frustration, but all the major nicities are there (albeit always in an OO form). Many of the core concepts are similar, yet are made available in a way that will be far more comfortable to newcomers than is Perl. For instance, every object inherits a .to_s() method—much simpler than explaining the ins, outs & special cases of Perl's stringification rules.
The OO nature goes right to the core of the Ruby (everything is an object). The descriptive OO concepts used are those of message passing from SmallTalk, which will also be familiar to Objective-C programmers. The "every call is a method" style will also be familiar to (very serious) JavaScript/ECMAScript programmers. The book authors also happily point out where Ruby adheres to true Object Oriented style where Java strays.
In short, it seems to combine all the good bits of the languages I love to use and love to admire.
When I have done more research I will deliver my verdict as to whether there is Ruby in my future or not.
Everything is an object?:
Literally everything is an object. There is no exception for strings or numbers (unlike some other OO languages), although you can use simple operators on objects (via operator overloading). For example, look at this example adapted from chapter two of the Ruby book
product1 = "Spam" product2 = product1 product1[1] = 'h' product1 is: "Sham" product2 is: "Sham"product1 and product2 are local variables that each contain a reference to the same String object (which was magically brought into being by the double-quoted inline string literal. A lot like perl objects really.
The biggest thing that's NOT like perl is that data types don't automatically coerce based on context. So you can't, for instance, do something like 5 + "5" which really sucks for file handling etc.
Code blocks:
Gratifyingly, Ruby has a very clean implementation of code blocks/closures/anonymous subs (depending on your language speak). Once again, nothing that you can't do in Perl (and i'm not sure i like the do ... end syntax), but such a clean, genuine OO, implementation is an absoulte joy.
Ranges:
In Ruby, a range is not a list—it's, well, a Range. An object of type Range that is, and Ranges have some rather nice properties. Take the following code example adapted from this chapter of the Ruby book:
fileHandle.each do
print if /start/../end/
end
It does what it looks like it's meant to do—prints any line in the input file that falls in between a line matching the regex /start/ and the one matching /end/. Not even Perl is that cool :) And if it was, Perl would call it DWIM—Ruby calls it the principle of least surprise...Update: Of course Perl's flip flop operator can have the same effect - which should be no surprise to me ;)
01:48 PM, 23 Jan 2005 by Mark Aufflick Permalink | Short Link








Perl's a jewel.
Perl has a magic flip-flop operator which does *exactly* the same thing you just wrote. i.e. while (<>) { print if /start/ .. /end/; } Read this: http://www.perl.com/pub/a/2004/06/18/variables.html It was actually in the test you passed(?) for your job :-)
by Unregistered Visitor on 01/28/05